# Costs: deducted when a prize is collected

Decision of 2026-11-22.

## The rule

- **Nothing is kept from sales.** The pot (and, in lotto, the prize fund) is **everything sold**: numbers × price.
  The tip is separate: it goes to development and is never part of the pot.
- **Costs** (hosting, domain, Lightning fees and development) are a public, announced percentage of each draw
  (`houseFee` in `config.json`; in lotto, `lotto.houseFee`). 3 % today, **5 % cap** in the code.
- They are deducted **from each prize when the winner collects it**: the winner receives
  `prize − ⌊prize × % ⌋`. Rounding is down to the sat, **per prize**, in the winner's favour
  (two prizes of 33 sats at 3 % pay 0 + 0, not ⌊66 × 3 %⌋ = 1).
- **If nobody collects a prize, nothing is deducted**: the whole amount goes back to prizes.
- The figures of the pot shown on the website are always the gross sales.
- The **Lightning fees** paid to send the prizes are paid out of the costs and are **not broken down anywhere**
  (decision of 2026-12-02): the Treasury shows only the costs (the % and what was collected), the relay board books a
  fee against the «Costs» account (no separate account), and the panel only shows the costs %. The server still records
  `feeSat` per payment when the wallet reports it, for its own audit.

## Where it lives in the code

| Piece | What it does |
|---|---|
| `common.js` · `buildState` | `pot = gross`, `house = 0`; `houseFee` is the % that will apply to each prize |
| `lotto.js` · `computePrizes` | `house = 0`, `fund = sales` |
| `purchases.js` · `buildResults` / `lotto.js` · `buildResultsLotto` | publish `house: 0` and `costs: <%>`; prizes in gross |
| `purchases.js` · `prizeCosts`, `costsPctOf` | costs of one prize and the % of a results file (old results without `costs` take nothing more: they already deducted at sale) |
| `purchases.js` · `checkClaim` / `prizesForClaim` | each prize carries `gross`, `costs` and `sats` = what is paid; `total` is the sum of `sats` |
| `server/lib/core.mjs` | the results' `costs` must be the event's %; the invoice must be for the net amount; `k=payment` publishes `sats` (paid), `prize` (gross) and `costs` |
| `treasury.js` | costs collected = Σ costs of the prizes **already paid**; nothing for unpaid or expired ones |
| `scripts/verify-draw.mjs` | with `costs`, it requires `house = 0` and `costs ≤ 5 %` |
