A House Divided A House DividedDocumentation
↵
Changelog
Game Design/Economy & Finance

Interbank Lending and Bank Resolution

Last updated 2026-10-29
Source files

Summary#

This covers three related pieces of the private banking system: the interbank market and central-bank margin line (), what happens to a bank's outstanding loan book after it fails (), and the NPP-run banks that seed into every eligible country (). All three sit inside the wider private banking system in src/lib/banking/, which also covers charters, deposits, reserves, capital adequacy, the discount window, and deposit insurance (not documented here). Every path in this doc is gated behind the privateBankingEnabled flag on gameConfig (), with the exception of NPC bank seeding (see Configuration).

Player guide: Interbank Lending (NPC banks and the wider banking system: Private Banking)

Rules#

Constants#

Constant Value Source
INTERBANK_MAX_SHARE_OF_LENDABLE 0.5 (provisional)
CB_MARGIN_SPREAD_PP 1.5 percentage points over prime (provisional)
CB_MARGIN_COLLATERAL_FRACTION 0.5 of prop book mark value (provisional)
ARREARS_DEFAULT_TURNS 8
TURNS_PER_YEAR 48
NPC_BANKS_PER_COUNTRY 2 (provisional)
NPC_BANK_CAPITAL_BUFFER_MULTIPLIER 3 (provisional)
NPC deposit-offset target lower quartile of the corridor: min + 0.25 * (max - min) (corridorDepositTarget)
NPC lending-offset target corridor midpoint
Interbank rate chosen by the lender per loan, at least 0 (no maximum in the schema)
Float tolerance for cap and payment comparisons 1e-9 interbank.ts, rules/interbankServicing.ts

Interbank lending (interbank.ts)#

A deposit-taking bank (retail or universal charter) lends non-reserved cash to a bank running a prop book (investment or universal charter). This is separate from a retail bank's ordinary loan book: interbank loans are not part of totalLoans and are tracked on their own InterbankLoan documents plus a running bankCharter.interbankDebt on the borrower.

Eligibility#

Sizing constraints#

INTERBANK_MAX_SHARE_OF_LENDABLE = 0.5   // provisional, src/lib/banking/rules/decide.ts

Lendable headroom is computed via getLendableHeadroom(lenderCharter, reserveRatio) (), which is max(0, cashBackedDeposits x (1 - reserveRatio) - totalLoans), with reserveRatio = getReserveRequirement(db, currency). Only cash-backed deposits count: player pointer balances never arrived as cash. The lender may place at most 0.5 x headroom on the interbank market, checked as a running total across all of that lender's current interbank loans (sumLenderInterbankOutstanding, summed over status: "current"). A new loan is rejected if it alone exceeds the cap, or if adding it to already-outstanding interbank lending would exceed the cap. Separately, the lender must have enough liquid cashReserves to cover the amount.

Origination (lendInterbank)#

Cash moves lender reserves to borrower reserves. An InterbankLoan document is created:

{
  lenderCorporationId, borrowerCorporationId, currency,
  principal, outstanding, ratePercent, originatedTurn,
  status: "current"
}

The write sequence is: insert loan, debit lender bankCharter.cashReserves (conditioned on cashReserves >= amount), credit borrower cashReserves and increment bankCharter.interbankDebt. Each step is guarded and the function unwinds (deletes the loan doc, refunds the lender) if a later step's conditional update fails to match, since the code notes standalone Mongo has no transactions. A bank_interbank_lend transaction is emitted via emitTx.

Repayment (repayInterbank)#

Repays principal only, capped at min(amount, loan.outstanding). Cash moves borrower to lender; bankCharter.interbankDebt and loan.outstanding both decrease by the repaid amount. If the lender-credit step fails after the borrower has already been debited, the code compensates by crediting the cash and debt back onto the borrower rather than losing it. Loan status flips to "repaid" once outstanding <= 0; arrearsTurns resets to 0 on any repayment.

Interest servicing (turn-phase)#

serviceInterbankAndCbMargin () runs every banking turn (idempotent via lastProcessedTurn !== turn), independent of whether any deposit-taking bank needs a servicing pass. It processes every InterbankLoan (collection interbankLoans) with status: "current", and only when prop trading is enabled.

Per loan (serviceOneInterbankLoan, ; the pure decision is decideInterbankService in ). Cash legs and the loan-record update land together as one journaled transition keyed per loan per turn (interbank-interest:<loanId>:<turn>), so a retried turn cannot pay twice:

interestDue = outstanding x (ratePercent / 100) / TURNS_PER_YEAR   // perTurnInterestOn, TURNS_PER_YEAR = 48
payment = min(interestDue, borrower's available cashReserves)

Interest moves cash from the borrower's to the lender's bankCharter.cashReserves. Principal is never collected here, only through repayInterbank.

Lender-side failure (bankSolvencyTurn.ts)#

If the LENDER on an interbank loan fails, writeOffLenderSideInterbankOnFailure marks every InterbankLoan where that corp is lenderCorporationId and status: "current" as "defaulted". The code is explicit that the borrower keeps the cash and the loss is absorbed as an unrecoverable write-off on the failed lender's estate; chasing the borrower for early repayment is treated as compounding one failure into a second. This function does NOT touch claims against the failed bank (i.e. where it is the borrower), those are settled separately, in priority order, by returnDepositBook during the resolution sweep (household book and central bank first, then lenders pro rata, per interbankResolution.test.ts).

CB margin line#

A separate facility: prop-book-collateralized borrowing directly from the country's central bank, available to the same investment/universal charters.

CB_MARGIN_SPREAD_PP = 1.5                 // provisional, src/lib/banking/rules/decide.ts
cbMarginRatePercent(primeRate) = max(0, primeRate + 1.5)

CB_MARGIN_COLLATERAL_FRACTION = 0.5       // provisional, src/lib/banking/rules/decide.ts
maxDebt = 0.5 x propBookMarkValue

CB margin interest is serviced in the same pass: each turn the bank pays cbMarginRatePercent(prime) on its interest-bearing margin debt (margin debt minus any liquidity advance, interestBearingCbMarginDebt, ), and the discount window facility is serviced alongside it, from the bank's available cash.

drawCbMargin: collateral check is cbMarginDebt + cbMarginArrears + amount <= maxDebt, i.e. unpaid interest arrears count against the line's headroom too (the code notes this is deliberate, a bank that cannot service the margin loses headroom rather than silently borrowing its own arrears). On draw, cash is CREATED into bankCharter.cashReserves (+amount) and bankCharter.cbMarginDebt increases by the same amount; the country's centralBanks.netMoneyCreatedLifetime increases correspondingly. This mirrors the discount window: originating the loan does not debit any CB pool.

repayCbMargin: repay amount is min(amount, cbMarginDebt, cashReserves). Cash is DESTROYED from the bank's reserves (mirror of creation on draw) and netMoneyCreatedLifetime decreases by the same amount.

Both draw and repay emit bank_cb_margin_draw / bank_cb_margin_repay transactions with the counterparty recorded as "{country} central bank".

API surface#

Dead bank loans (deadBankLoans.ts)#

Handles loans a FAILED or REVOKED bank made as a LENDER that were never resolved when the charter died. The module's own comment states the prior behavior explicitly: the banking turn only services banks with an active charter, so once a bank's charter left that state its outstanding loan book simply stopped being serviced, borrowers stopped paying, the asset sat at full value on a dead charter forever, and any recovery reached nobody.

Which banks qualify#

findDeadBanksWithLoans selects every corporation with bankCharter.status in ["failed", "revoked"], plus the archived charter snapshots in the charter history whose status was failed or revoked (a bank that failed and was chartered again leaves its old book behind under the earlier epoch). Each is marked resolved: true when its lifecycle stage allows windDownEstate (), i.e.:

One recovery owner is kept per originating charter epoch, preferring the resolved snapshot.

Where recovered cash goes (recoveryTargetFor)#

Servicing loop (processDeadBankLoans, called from )#

For all dead banks it reads bankLoans in one query for their bankCorporationIds, covering character, corporation and npcBulk (household tranche) borrowers, status in ["current", "arrears"], and lastProcessedTurn !== turn (idempotency guard). If there are matching loans, it resolves the target (estate or insurer) and then services each loan SERIALLY within that bank (not in parallel), because two loans from the same borrower must see each other's debit exactly as the live per-bank servicing path does. The actual per-loan collection math (interest, arrears, principal) is injected as a serviceLoan callback from bankingTurn.ts rather than owned by this module, specifically so this file does not depend on the turn file that depends on it.

A whole epoch's book is serviced in at most two journaled moves: named loans and household tranches share one, and construction loans take a second because they hold a lease and a loan lock. Loans neither move can carry (an untagged legacy loan, a borrower with no document, a corporation whose book spans currencies, anything another receipt still owns) fall back to the per-loan path. Every move uses a deterministic per-turn key, so a retried turn cannot charge a borrower twice.

Returned summary: { loansServiced, recoveredToEstate, recoveredToInsurer }, all zero if there are no dead banks with loans.

NPC banks (npcBanks.ts)#

NPP-owned (non-player-party) retail banks seeded into eligible countries to give the private banking system counterparties and market depth without requiring player-run banks in every country.

Seeding (seedNpcBanks)#

NPC_BANKS_PER_COUNTRY = 2                        // provisional
NPC_BANK_CAPITAL_BUFFER_MULTIPLIER = 3            // provisional

For every country in ALL_COUNTRY_IDS:

Seeding itself is NOT gated on privateBankingEnabled (comment: "gameConfig is never mutated", the bypass is scoped to charter issuance only, not a flag flip). Runtime turn behavior is gated (see below).

Runtime rate policy (runNpcBankPolicy / processNpcBankPolicyTurn)#

Turn-phase entry point processNpcBankPolicyTurn (registered as phase npcBankPolicyTurn in ) no-ops with a zero summary ({ banksChecked: 0, banksUpdated: 0 }) if isPrivateBankingEnabled() is false. It does NOT seed banks; seeding is a separate admin/bootstrap-time operation (, ).

When enabled, runNpcBankPolicy iterates every corp with ceoType: "npp", active bankCharter, and charter type retail or universal. For each, it fetches the country's rate corridors (getRateCorridors) and computes the targets: the deposit offset goes to the lower quartile of its range (min + 0.25 * (max - min), so incumbents price deposits lazily and leave room for player banks to win share), the lending offset to the midpoint. If the current depositOffset/lendingOffset has drifted from either target by more than 1e-9, both are reset via setBankRates. It does not set the reserve-holding or loan-book behavior, which the comment says comes from bankingTurn's NPC flows (not covered by this file).

Data#

Collection Fields Read or written Shown to players
interbankLoans lenderCorporationId, borrowerCorporationId, currency, principal, outstanding, ratePercent, originatedTurn, status (current, defaulted, repaid), arrearsTurns, lastProcessedTurn Written on origination, repayment, servicing, default Interbank state through the bank read model (GET /api/banking/corporation/[id]), to the bank's own CEO
corporations (bankCharter) cashReserves, interbankDebt, cbMarginDebt, cbMarginArrears, liquidity-advance portion of cbMarginDebt, status, depositorsResolvedTurn, insuranceResolutionTurn, depositOffset, lendingOffset, npcBankSeedKey (on the corporation) Read and written Own bank page; NPC offsets shape public rates
bankLoans bankCorporationId, borrowerType, status, outstanding, lastProcessedTurn Read and updated by dead-bank servicing Borrower sees their own loan
depositInsuranceFunds balance per currency Credited by late dead-bank recoveries (ensureFund first) Insurance fund balance
centralBanks netMoneyCreatedLifetime Raised by margin draws, lowered by repayments Money supply views
Charter history Archived failed or revoked charter snapshots Read to find old loan books No
bankMoneyMoves Journal of money moves keyed per loan or batch per turn Written No
gameConfig (_id: "default") privateBankingEnabled, bankPropTradingEnabled, bankContagionEnabled Read No
Transactions bank_interbank_lend, bank_cb_margin_draw, bank_cb_margin_repay Written Own transaction history

Configuration#

defines three flags read off gameConfig._id: "default" (resolved through the banking policy snapshot in ):

Flag Default Effect
privateBankingEnabled disabled; only an explicit true turns it on Master switch
bankPropTradingEnabled enabled when absent, requires banking on Gates interbank lending and the CB margin line
bankContagionEnabled enabled when absent, requires banking on Gates failure contagion (not covered by the three files here)

lendInterbank, repayInterbank, drawCbMargin, and repayCbMargin all check isPrivateBankingEnabled() && isBankPropTradingEnabled() and return an error if either is false. The two interbank API routes (bank/interbank/loans, bank/interbank/margin) separately gate on isBankPropTradingEnabled() and return 404 if off. Flag-off is a read-only freeze, not a drain: existing books stay as they are.

NPC bank seeding (seedNpcBanks) is explicitly NOT gated on privateBankingEnabled, charters are issued through the real issueCharter path with a skipFlagCheck bypass, so NPC banks exist in the world regardless of the flag. Runtime NPC bank behavior (processNpcBankPolicyTurn, the turn-phase entry point) IS gated: it no-ops and returns a zero summary when private banking is off.

Other settings that change behaviour:

Setting Where set
World preset and era unit scale (which countries seed, bank naming) loadWorldPreset, loadWorldEraUnitScale in
Country HQ state for NPC banks NPP_CAPITAL_STATES in
Legal charter types per country and command-economy gating
Reserve requirement per currency (sets lendable headroom) bankReserveRequirement on the central bank, era default otherwise (getReserveRequirement)
Rate corridors (NPC offset targets) getRateCorridors

There are no per-scenario overrides for the three provisional constants; they are code defaults.

Timing#

Order within a turn ():

  1. npcBankPolicyTurn runs first, before bankingTurn, so corrected NPC rate offsets price this turn's deposits and loans.
  2. bankingTurn (): live-bank loan books, then dead-bank loans (processDeadBankLoans), then serviceInterbankAndCbMargin.
  3. recomputeSharePrices, then bankSolvencyTurn (): failure detection, contagion and the lender-side interbank write-off, so prop-book marks use fresh prices.
flowchart TD
  A["npcBankPolicyTurn: reset NPC offsets"] --> B["bankingTurn: live loan books"]
  B --> C["processDeadBankLoans"]
  C --> D["serviceInterbankAndCbMargin: interest, defaults"]
  D --> E["recomputeSharePrices"]
  E --> F["bankSolvencyTurn: failures, lender-side write-off, resolution waterfall"]

Player actions (originate, repay, draw, repay margin) run immediately on the API call, outside the turn. NPC bank seeding happens only at bootstrap or by admin action.

Worked trace#

Interbank loan#

A retail bank has cash-backed deposits of 12,000,000 with a 10% reserve requirement and 9,800,000 of loans: headroom is 12,000,000 x 0.9 - 9,800,000 = 1,000,000, so its interbank cap is 500,000. It already has 200,000 out.

CB margin#

Prime rate 4% gives a margin rate of 5.5%. A prop book marked at 2,000,000 gives a debt ceiling of 0.5 x 2,000,000 = 1,000,000. With 600,000 drawn and 50,000 of interest arrears, the most the bank can draw is 1,000,000 - 600,000 - 50,000 = 350,000. Each turn's interest on 600,000 is 600,000 x 0.055 / 48 = 687.50. Drawing 350,000 creates 350,000 of cash in the bank's reserves and raises netMoneyCreatedLifetime by the same amount; repaying 350,000 later destroys it.

Dead-bank recovery#

A borrower owes a failed bank 1,000 of interest this turn. If the bank's estate is not yet resolved, 1,000 lands in its bankCharter.cashReserves and the pending waterfall distributes it. If the bank is resolved or revoked, the same 1,000 is credited to the currency's depositInsuranceFunds.balance. The summary reports recoveredToEstate: 1000 or recoveredToInsurer: 1000.

NPC bank#

If a country's charter capital requirement is C, each of its two NPC banks starts with 3C, of which C is posted in the charter. For an illustrative corridor of offsets from -1.0 to 3.0, the deposit offset target is -1.0 + 0.25 x 4.0 = 0.0 and the lending offset target is the midpoint 1.0.

Edge cases and limits#

Invariants#

Invariant Enforced by
Money is conserved across lend, repay, interest, failure and resolution , (balanced_transfer, guarded_debit),
Interbank outstanding per lender never exceeds 0.5 x headroom decide.ts and lendInterbank; ("caps lend amount")
Margin debt plus arrears never exceeds 0.5 x prop mark on a draw drawCbMargin; interbank.test.ts,
Margin draw creates exactly the cash it adds to debt, and repayment destroys it interbank.test.ts ("destroys cash on repay", "mirrors netMoneyCreatedLifetime")
A loan is serviced once per turn and cannot be paid twice on retry per-loan journal key; interbank.test.ts ("once per turn"),
A dead bank's loan is serviced once per turn, serially per bank lastProcessedTurn guard; , deadBankLoans.batch.test.ts
NPC seeding is idempotent npcBankSeedKey; ("is idempotent")
bank_accounting_identity: assets equal liabilities plus equity invariants.ts, invariants.test.ts
Defaulting never moves cash by construction in decideInterbankService; interbank.test.ts ("writes off to lender (no cash recovery)")

Failure and recovery#

Connections#

Driven by:

Affects:

Key files#

Tests#

Area Test file
Interbank origination, repayment, margin, servicing and default
Lender failure and estate settlement order
Margin arrears shrink the line
Interbank income in the banking turn
Dead-bank discovery, routing, batching , deadBankLoans.batch.test.ts, deadBankLoans.shapes.test.ts
NPC seeding and policy ,
Solvency phase
Money conservation and crash recovery , journalCrashInjection.test.ts
Pure rules , facilityInterest.test.ts, invariants.test.ts

Gaps: no test file targets serviceInterbankAndCbMargin or decideInterbankService directly (they are exercised through interbank.test.ts and the banking-turn integration test), and the interbank rate has no upper-bound test because there is no bound.

Known issues and history#

Last checked: 2026-10-29, version 1.18.0

Ask