Intent API: movements and transfers over raw envelopes
- Status: accepted
- Authors: Cesar Rodas
- Date: 2026-06-29
- Targeted modules:
kuatia-types (Movement, Transfer, TransferBuilder), kuatia (ledger::resolve)
- Associated tickets/PRs: N/A
Context and Problem Statement
In a UTXO-style model (ADR-0001) a commit works on concrete postings in the end.
It names the exact postings to consume, the postings to create, and the change.
A caller could assemble that itself: pick the inputs, compute the change and
balance each asset. That is easy to get wrong, and it couples application code
to the internals of the ledger. So what is the public unit of intent, and
where does the translation into concrete postings happen?
Decision Drivers
- Ergonomics and safety: a caller must express what it wants, as in "pay B
40 USD from A". It must not select a UTXO by hand.
- Keep the UTXO model an implementation detail: neither the selection nor
the change must reach application code.
- Determinism and idempotency: one intent must always resolve the same way,
and a second submit of it must do nothing.
- Composability: multi-account, multi-asset events (FX, compound entries)
must be expressible as one atomic intent.
Considered Options
Option 1: Callers build Envelopes directly (raw UTXO API)
The public API is the resolved form. A caller chooses the consumed posting ids
and constructs the created postings.
Pros:
- Good, because it is as explicit as it can be and gives full control. That
helps an FX flow, and a flow tuned by hand.
Cons:
- Bad, because every caller re-implements the posting selection, the change and
the per-asset balance. Each of those is easy to get wrong.
- Bad, because it couples application code to posting ids and the UTXO model.
- Bad, because there is no natural high-level vocabulary such as pay, deposit
and withdraw.
Option 2: A two-layer API: intent (Movement/Transfer) to resolved (Envelope)
A caller expresses intent as Movement { from, to, asset, amount } values, and
a Transfer groups them. TransferBuilder::pay/deposit/withdraw/movement
builds the group.
The ledger's resolve() turns that intent into a concrete Envelope. It
selects the postings and computes the change. The envelope is what the ledger
validates and commits. The raw envelope path stays available internally, for
reverse() and for a hand-built multi-asset envelope.
Pros:
- Good, because the common case is one call, and the UTXO mechanics stay hidden.
- Good, because the intent is small and serializable, and
resolve is
deterministic. So the resolved Envelope has a stable content id, which gives
idempotency. See the record on the content address.
- Good, because a compound event and a multi-asset event are only several
movements that commit atomically. A deposit and a withdrawal are movements
against a boundary account.
- Good, because the escape route still exists for a flow that the intent
vocabulary cannot express. Build an
Envelope directly.
Cons:
- Bad, because a reader must understand two representations, the intent and the
resolved form. The word "posting" is also a noun here and not the accounting
verb.
- Bad, because idempotency keys on the id of the resolved envelope. Resolution
must therefore be deterministic, or a second submit does not dedupe. The
resolver must hold that property.
Decision Outcome
Chosen option: Option 2, the two-layer intent API. It keeps the UTXO model
an internal detail. It makes the common operations trivial and safe. It yields a
deterministic resolved Envelope, whose content id gives idempotency.
It also still accepts an envelope that a caller built in advance, for a flow
that needs one.
Positive Consequences
TransferBuilder offers pay, deposit and withdraw, which are preferred
over a raw movement. One Transfer can carry many movements that commit
atomically.
commit(transfer) is a read-only resolve and then commit_envelope. The
saga and the recovery both work on the resolved envelope (see ADR-0002 and
ADR-0003).
- A deposit resolves to two movements that cancel to a net debit of zero on the
system account. So it needs no posting selection.
Negative Consequences
- There are two representations to document, and the caveat on "posting" as a
noun and as a verb. See accounting-mapping.md.
- Resolution must stay deterministic, so that a second submit of one intent
dedupes.
Links