Economy
The Integer Double-Entry Ledger
Every balance is a signed 64-bit integer in cents. Every transaction sums to zero. Why floating-point money is banned outright and what that discipline catches.
The fifth invariant is the least glamorous and the most load-bearing: all monetary balances and settlements use signed 64-bit integer cents inside an append-only double-entry ledger where SUM(delta_cents) = 0 per transaction.
Floating-point currency arithmetic is prohibited. Not discouraged — prohibited.
Why floats are disqualified
0.1 + 0.2 is 0.30000000000000004 in IEEE 754 double precision. In a game that computes a 6% exchange tax on a few million trades, those residuals accumulate into real divergence, and the divergence is silent. There is no exception thrown and no log line. There is only a number that is slightly wrong, compounding.
Worse, floating-point error is exploitable. A player who finds a rounding direction that favours them can run it a few hundred thousand times. Any economy with a trade loop and float arithmetic eventually meets somebody who has done exactly that.
So every balance is a BIGINT of cents in PostgreSQL and a bigint in TypeScript. 100 means one dollar. Division always specifies its rounding direction explicitly, and the rounded remainder goes somewhere real — usually the sink — so nothing is created or destroyed by accident.
Double entry, enforced
Money never moves in a single write. A spot trade is not "subtract from buyer, add to seller"; it is one transaction with legs that must sum to zero:
| Leg | Account | Delta (cents) |
|---|---|---|
| 1 | Buyer cash | -1 000 000 |
| 2 | Seller cash | +940 000 |
| 3 | Exchange tax sink | +60 000 |
-1 000 000 + 940 000 + 60 000 = 0
If any code path produces legs that do not sum to zero, the transaction is rejected. A bug that would otherwise quietly mint $600 instead fails loudly at the moment it is written.
The ledger is append-only. Corrections are new compensating entries, never edits. That means the history of every cent is reconstructible, which matters enormously the first time somebody asks why their balance is what it is.
Lock ordering
Double entry across concurrent players means row locks, and row locks mean deadlock risk. TycoonGlobal fixes a global acquisition order:
ledger_accounts -> country_subsidiaries -> inventories -> market_orders
Every transaction takes locks in that order, so two transactions touching the same rows can never hold what the other needs. Deadlocks become structurally impossible rather than statistically rare.
What the discipline caught
Running the economy simulator for 90 simulated days with 1,000 agents produces roughly 2.9 million transactions across 2,160 hourly ticks. At the end, the money-supply identity is asserted:
M_end = M_start + faucet - sinks
Measured drift: $0.
That number stayed at zero through a long sequence of economic changes — rewriting the retail demand model, adding pro-rata wages for partially utilised plants, adding a marketing layer with its own CAC and LTV accounting, changing how agents plan production. Every one of those changes moved real money around in new ways. None of them leaked a cent, because a leak would have failed the assertion immediately.
That is the actual argument for integer double entry. It is not that floats are inelegant. It is that an economy with this many moving parts needs a test that cannot be satisfied by code that is almost right.
Where the rule bites
Three places where the constraint forces better design:
Percentages. A 6% tax on an odd number of cents has a remainder. It is always rounded in the sink's favour and the remainder is burned, so the identity holds and nobody can farm the rounding.
Interest. Weekly loan interest is computed on the integer principal and rounded once, not accrued per-tick in a float.
Valuations. Net worth is cash + book CAPEX + VWAP inventory - debt, all integer. The 24-hour VWAP used for inventory is itself an integer price in cents, so leaderboards are reproducible from the ledger rather than approximated.
None of this is visible in the game. That is the point.