Codemojex · C6.3 · a dive of The Revenue Ledger and the KeyShop
Cash-out and the treasury.
Everything so far moves money inward. Cash-out is the one outward rail — diamonds leaving for TON, USDT, or RUB. It is forward — cm.8: cm.7 designed for the seam and built none of it, quarantining the regulatory and fraud weight into its own rung. The lesson is that the outward rail needs no new ledger verb and no new account — it is a house debit through the same signed house_post. What cm.8 adds is not machinery but policy.
Grounding — the shipped seams: wallet.ex (house_post/5 signed, balance/1 / locked_diamonds) · key_shop.ex (the create_order rate snapshot) · rails.ex · the webhook (WHK) forward shape. The rates poller, the hold, KYC/AML, and treasury reconciliation are stated forward-tense.
house_post/5 already books a signed delta — the house swings negative on the deposit_seed debit today. A withdrawal is a negative revenue_ledger.delta through the same primitive: no new verb, no new account. Shipped.The seams are already shipped
wallet.ex · balance/1The outward rail is a small addition rather than a new system because four seams already exist. The signed house_post admits a negative delta (proven by the seed debit); create_order pins a rate snapshot at creation and never re-reads the live rate; the players.locked_diamonds column is live, and balance/1 already reports available_diamonds as diamonds − locked_diamonds; and the WHK schema is the designed-forward idempotency shape for a push rail. A hold window is a locked_diamonds move — the column exists; only the policy is new.
def balance(player) do
case Repo.get(Player, player) do
nil ->
nil
p ->
p
|> Map.from_struct()
|> Map.drop([:__meta__])
|> Map.merge(%{available_keys: p.keys,
available_diamonds: p.diamonds - p.locked_diamonds}) # the hold seam
end
end
The signed primitive is C6.1: house_post/5 books a signed delta, so the withdrawal debit needs no new verb. This dive is the outward direction the design points at but has not built.
The withdrawal pipeline
forward · cm.8The withdrawal runs five stages. Select one to see the shipped seam it rests on and the forward policy it adds — only the middle stages are new; the endpoints are the same signed ledger and the same rail set the KeyShop uses.
create_order’s pinned rate snapshot, which records rate_minor/rate_pair/rate_source/rate_quoted_at and never re-reads the live rate. The snapshot discipline is shipped; the rates table and its poller are forward.rates table, the poller, the hold window, and the KYC/AML gate are the next rung’s work; only the endpoints — the signed house_post debit and the Rails set — exist today.What cm.8 adds
the forward policyThe regulatory and fraud weight is quarantined into cm.8 on purpose: the inward rails ship safely without it, and the outward rail cannot ship without it. Three additions, all forward, each expressed over a shipped seam.
- A
ratestable with a poller. The floating quote, pinned per withdrawal at request time — thecreate_ordersnapshot discipline, inverted for the outward direction. forward - KYC/AML and the 21-day hold. The compliance gate the outward direction requires, expressed over the shipped
locked_diamondsseam — a hold locks diamonds, soavailable_diamondsfalls while the balance does not. forward - Treasury reconciliation. The platform’s on-chain balances reconciled against the signed
revenue_ledgerdebits — the ledger is the book of record, the chain the counterparty. forward
The design’s rule holds: transparent margin levers, never undisclosed house players. The outward rail is the last piece of the money story — the house’s book (C6.1) and the pay-in (C6.2) are shipped; the withdrawal is where the platform’s obligations to a regulator begin, so it waits for its own rung.
References
sources · relatedSources
- Ecto — Repo.transactionthe all-or-nothing debit-and-book transaction a withdrawal runs
- Helland — Life Beyond Distributed Transactionsentities behind boundaries and idempotent activities; the treasury and the confirmation
Related
- C6.1 — The revenue ledgerthe signed ledger the debit posts to
- C6.2 — The KeyShopthe inward rails the withdrawal mirrors
- BCS — the architecture lawthe ledger law behind the books