The account ledger
The append-only record behind every account: which events get an entry, what each entry carries, and why every balance the account has ever shown is derivable from it.
What the ledger records
The ledger is an append-only record of every state-changing event in an account. One entry per event, in the order it happened.
The attachment, swap, and queued-swap events come from promotion and swaps; the Pause and Stop events come from the account state machine.
Deposits and withdrawals each record as their own ledger entry and adjust the account balance when they occur.
Capital is ledger-driven
Capital moves only as a result of ledger events. There is no field that overwrites the balance.
- The initial-capital event seeds it.
- Trades move it.
- Deposits and withdrawals adjust it.
The balance at any point is the sum of every entry up to that point. To reconstruct the account's capital on a past date, read the ledger up to that date. This is why sizing and capital inside the account trace back to a single event log rather than a mutable number.
Append-only
Entries are added, never edited and never removed. Once an event is written, it stays exactly as written.
The consequence: the ledger is a complete, ordered history of everything that changed the account, and nothing in that history can be rewritten after the fact. Every balance the account has ever shown is derivable from it and reproducible from it.
Snapshot history through the ledger
When a Portfolio is swapped, the previous snapshot is not discarded. The swap event in the ledger retains access to the prior snapshot.
Every Portfolio the account has ever held stays reachable through its swap event, read-only, alongside the current snapshot. Walk the ledger's swap events to move back through the account's Portfolio history.