> ## Documentation Index
> Fetch the complete documentation index at: https://docs.skia.money/llms.txt
> Use this file to discover all available pages before exploring further.

# Invoices

> The invoice model: EIP-712 claims that resolve into Orders, the nine-kind event taxonomy, status as a pure fold, and the money law — integer math, non-compounding late fees, superseding disputes.

# Invoices

An invoice on Skia is **not an Order**. It is a signed **claim** — an
issuer-declared obligation — that **resolves into Orders** at payment time,
settling through the existing commit/reveal rail. The claim layer lives on
`/v1` (eight paths); the settlement layer stays on `/api`, byte-identical.

## The claim

The claim is an EIP-712 `InvoiceClaim`, signed by the **issuer**. The
verifying implementation must hash **exactly** this canonical encodeType —
the same byte-match discipline as the Order typehash:

```text theme={null}
InvoiceClaim(address issuer,address debtor,uint256 amount,string currency,
uint64 settleChainId,uint64 issuedAt,uint64 dueAt,uint32 gracePeriodSeconds,
uint32 lateFeeBpsPerDay,string feeBearer,string invoiceId,string memo,
string externalRef)
```

Per EIP-712, string members hash to keccak256 of their UTF-8 bytes, and **all
members are always encoded** — an absent `externalRef` encodes the empty
string, so the digest is total. No dynamic-member omission.

### The domain (D-INV-1)

The claim's signature is anchored to the rail where it resolves. The
program-constant-domain alternative was considered and **rejected**.

| Field | Value |
| - | - |
| `name` | `Skia InvoiceClaim` |
| `version` | `1` |
| `chainId` | the claim's `settleChainId` |
| `verifyingContract` | the pinned `SwapERC20` on that chain |

### The claim hash

The identifier every countersignature references — pinned as the **EIP-712
digest itself**:

```text theme={null}
claimHash = keccak256(0x19 ‖ 0x01 ‖ domainSeparator ‖ structHash)
```

### Roles

| Party | Powers |
| - | - |
| **Issuer** (creditor) | signs the claim; the only party that can CREDIT\_NOTE, VOID, or DEFAULT |
| **Debtor** | the only party that can ACK, REJECT, DISPUTE — and signs the payment Orders |

Signatures are **role-bound**: issuer and debtor are struct fields of the
claim, so recovery proves the signing role.

## The event taxonomy — nine kinds

Every state-changing act is **a signature + an event**. Events are
append-only; corrections are new events, never edits.

| Event | Actor | Signature form |
| - | - | - |
| `ISSUE` | issuer | the claim signature itself |
| `ACK` / `REJECT` | debtor | countersignature over the **same claim digest** — no second EIP-712 type |
| `DISPUTE` | debtor | countersignature; `disputedAmount` is ledger-recorded |
| `CREDIT_NOTE` | issuer | issuer-signed `CreditNotice` — the **only** second EIP-712 type |
| `RESOLVE` | ledger | **derived, never client-posted** — credit-note coverage of the open dispute, or mooting on full settlement |
| `PAYMENT` | debtor | the debtor's existing **Order signature is the payment's signature** — the Swap event is the complete receipt |
| `VOID` | issuer | issuer signature (withdrawal) |
| `DEFAULT` | issuer | issuer signature, only after `dueAt + gracePeriodSeconds` |

## Status is a pure fold

Status is **never stored**. It is recomputed at read time from the event list
(property-tested: no unreachable states; overdue and partial are always
derivable):

> [accordion] Fold skeleton
>
> * `ISSUE` → **ISSUED**
> * `+ACK` → **ACKNOWLEDGED** — the credit moment: an acknowledged invoice IS a receivable
> * `+` first RECEIPTED payment while outstanding is above zero → **PARTIALLY\_PAID**
> * outstanding reaches zero → **SETTLED** (terminal)
> * `+REJECT` → **REJECTED** (terminal)
> * `+VOID` → **VOIDED** (terminal)
> * `+DEFAULT` → **DEFAULTED** (terminal)

> [accordion] The VOID guard
>
> VOID is **refused once `paidToDate > 0`** (`409 INVOICE_STATE_INVALID`). A
> VOID after money moved would strand debtor funds on the out-of-band refund
> path. VOID stays a clean-withdrawal instrument for unpaid claims; moneyed
> claims unwind with credit notes (`creditedToDate` does not trip the guard).

> [accordion] DEFAULT is an asserted signal
>
> DEFAULT is **issuer-declared after grace** — a reputation signal, NOT
> cryptographic proof of non-payment (the debtor may have paid on a rail
> outside the issuer's view). Only valid after `dueAt +
>         gracePeriodSeconds`, only from a non-terminal state with outstanding
> above zero. Decentralized default attestation is deferred to Phase 3.

## The money law

Integer atomic-unit arithmetic only — floats never touch money on this
surface.

* `outstanding = max(0, faceAmount − paidToDate − creditedToDate)`
* **Payments reduce principal only. Credit notes reduce principal only.**
  A note closing a dispute is a FLAG transition, never a second deduction.
* **Late fee** — a non-compounding, read-time accrual on the undisputed
  remainder:

```text theme={null}
lateFeeAccrued = floor(undisputedOutstanding × lateFeeBpsPerDay × wholeDaysPastDue / 10000)
```

Whole days count from `dueAt + gracePeriodSeconds` (unix seconds, never
block numbers). **Fees never consume payments** — the late fee is a computed
number for reporting and policy, never a balance: it never increases
outstanding and never reduces a payment.

* **Disputes supersede, never sum** — the latest open DISPUTE's amount is the
  whole open disputed amount; a derived RESOLVE zeroes it. Disputes are a flag
  on the remainder, **not a payment blocker**.
* Once DEFAULTED, the **fee clock freezes at the DEFAULT event's recordedAt** —
  terminals are absorbing; a post-DEFAULT payment shrinks the fee, never grows
  the clock.
* Overage (paid + credited above face) surfaces as `surplus` and is settled
  **out-of-band** in Phase 1 (disclosed). Payments on VOIDED/REJECTED claims
  are recorded as events; refunds are out-of-band (no on-chain refund rail).

## Two clocks

| Clock | Value | Meaning |
| - | - | - |
| Order expiry | mint + 600 seconds | **settlement liveness** — the 10-minute window inside one payment attempt |
| Claim `dueAt` | unix-seconds timestamp, never a block number | **claim maturity** — grace and DEFAULT logic hang off it |

## Reading the ledger

* `GET /v1/invoices/{invoiceId}/receivable` — the fold view of one invoice
  (issuer or debtor only).
* `GET /v1/receivables` — cursor-paginated fold views for the calling party
  (`role`, `status`, `currency`, `settleChainId` filters; limit up to 100).

The `Receivable` carries the fold state plus orthogonal flags (`overdue`,
`openDisputedAmount`), the full event list (the audit trail is first-class),
and the derived `lateFeeAccrued`.

> [!NOTE]
>
> The event ledger discloses two Phase-1 trust boundaries: the ack/reject
> **decision word** and `disputedAmount` are ledger-recorded rather than covered
> by signatures. Phase 2 binds decisions into signed structs alongside a
> negotiation-transcript protocol.

> [!WARNING]
>
> Active-chain rule: the Phase-1 invoice service operates exactly ONE active
> settlement chain at a time (X Layer at ship). A claim whose `settleChainId`
> differs is refused at issue with `400 INVOICE_CHAIN_NOT_ACTIVE`. Payment
> attempts inherit the claim's chain — there is no per-request cross-chain
> routing.

## Where to next

* Pay one: [Settlements](https://docs.skia.money/concepts/settlements.md) — the attempt machine and the
  Order template law.
* How restrictions are encoded and checked: [Attestations](https://docs.skia.money/concepts/attestations.md).
* Drive the whole lifecycle end to end: [Invoice lifecycle example](https://docs.skia.money/examples/invoice-lifecycle.md)
  or through [MCP](https://docs.skia.money/mcp-server.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.