# Treasury

The treasury holds the protocol's external reserve, work-in-process, and started capital goods. It receives the post-commission tax from this Flap launch, buys parts, tapes out and starts machines, then deposits mined `$BEM` for holders.

This page defines what the treasury may hold and where BNB may be spent. Where funds come from: [Capital Flows](/flows). How `$BEM` is split: [Dividends](/dividends). Who may call: [Control Surface](/control).

Kit BNB is spent on Firsto orders and the TapeOut tape-out fee. The owner can withdraw what has not been spent. Flap pays native BNB. WBNB is forwarded only when a WBNB balance is actually in the contract.

## What the treasury can hold

### Undeployed reserve

BNB not yet spent. The source is the tax Flap dispatches after its commission. This is a kit budget, not a holder-redeemable reserve. No slice of the tax is reserved as a dividend or an LP add.

### Work-in-process

NAND and LATCH not yet taped out. Parts are ERC-1155 from Gates, bought on Firsto. They are inventory until tape-out. Tape-out is irreversible.

### Productive capital

Circuit NFTs from TapeOut, and miners already started on PodMining. The owner can send the NFTs to another address. After start, a machine cannot be stopped. Moving the NFT does not turn it back into BNB, and this treasury can no longer harvest it.

### BEM payable

`$BEM` sits here only until `deposit` succeeds. A refused deposit (`totalShares == 0`) leaves it here. After a successful deposit the balance is 0 and holders claim on the Flap Dividend. The treasury does not keep `$BEM` as its own share.

`$MTAPE` is not locked in the treasury. The `$MTAPE` you hold decides whether you can claim `$BEM`.

## One machine

The kit cannot be edited. The netlist is in the contract. Tape-out hashes it again and reverts on mismatch.

| Item | Value |
|---|---|
| NAND | tokenId 0, 1 per machine |
| LATCH | tokenId 1, 9 per machine |
| Task | 220 (Johnson-8) |
| Cycles / gates / samples | 16 / 10 / 256 |
| Window | 64 blocks after arm |
| Batch cap | Buy or tape-out, at most 10 machines |

```mermaid
%%{init: {"theme":"base","themeVariables":{"primaryColor":"#1a120c","primaryTextColor":"#f5ede4","primaryBorderColor":"#953307","lineColor":"#f46622","secondaryColor":"#221710","tertiaryColor":"#120d09","edgeLabelBackground":"#120d09","noteBkgColor":"#221710","noteTextColor":"#f5ede4","noteBorderColor":"#953307","actorBkg":"#1a120c","actorBorder":"#953307","actorTextColor":"#f5ede4","signalColor":"#f46622","signalTextColor":"#f5ede4","fontFamily":"inherit"}}}%%
flowchart LR
  Buy["buyKit<br/>kitBuyer only"] --> Tapeout["tapeout<br/>anyone"]
  Tapeout --> Arm["arm<br/>64-block window"]
  Arm --> Start["startJohnson<br/>task 220"]
  Start --> Harvest["harvest<br/>anyone"]
  Start -.-> Stop["stopMining<br/>reverts"]
  classDef hot fill:#f46622,stroke:#f46622,color:#120d09
  classDef dim fill:#120d09,stroke:#3a2416,color:#b9a693
  class Start hot
  class Stop dim
```

Start is terminal. There is no stop path. Each machine can be tracked by its `Taped` and `Started` events.

## Buying parts

Only kitBuyer can buy. One kit, or n kits: n NAND and 9n LATCH. n is at most 10.

The contract checks that the order is a Gates part, that tokenId and side are correct, that size is enough, and that it has not expired. It then pays `price × quantity × (1 + fee)` in BNB. Parts land in the treasury.

The contract does not check price. The script reads the official TapeOut quote and book (`api-tapeout.firsto.ai`) and posts the cheapest live Firsto venue ids. Nobody else can spend treasury BNB directly. kitBuyer can fill a more expensive ask. See [Risks](/risks).

If Firsto has no live asks, tax stays as treasury BNB. The production function stops. The destination does not change.

## Tape-out and start

Tape-out, arm, and start are permissionless.

Tape-out needs enough NAND and LATCH in the treasury, plus an approval to TapeOut, plus the tape-out fee. The new circuit NFT must be owned by the treasury. Ready kits are `min(NAND, floor(LATCH / 9))`.

This launch uses Johnson only. Other start entrypoints revert.

Start is two steps and cannot share a transaction.

1. `arm` opens a window for a machine that is not live, whose window expired, or that was never armed. The window is the next 64 blocks.
2. From the next block, while the window is live, `startJohnson` uses the arm-block `blockhash` and hangs the machine on PodMining.

An expired window needs a new arm. `startJohnson` uses about 6.2M gas, so it cannot start a batch. Batching applies to buying parts and tape-out only.

After start, the machine cannot be stopped. Commitment device: [Design Goals](/goals).

## External contracts

These contracts are not in this repo. Addresses are on BNB Chain. This launch depends on them keeping the current interface.

| Contract | Address | Use |
|---|---|---|
| Firsto V2 | `0x5cebB870dEdC02a709CE7e8416B1b83F3946F572` | Buy NAND / LATCH |
| Gates | `0xCC42ba5De07f01B472a5b14cF45aBcCA79Eb8087` | Parts, ERC-1155 |
| TapeOut | `0xb1024b89886B9a34Aa4ff5F31C411D708b20a14C` | Tape-out, treasury receives ERC-721 |
| PodMining | `0x7E2E0DC66a3bD9103E69b766afA62d9f7b697b46` | Arm, start, harvest |
| `$BEM` | `0x5ce033B2bFCa3Af30b3e8C8457DeaF776A8b695a` | Reward token, 8 decimals |
| Flap Portal | `0xe2cE6ab80874Fa9Fa2aAE65D277Dd6B8e65C9De0` | Curve, tax dispatch, Dividend |
| Pancake V2 | `0x10ED43C718714eb63d5aA57B78B54704E256024E` | Pool after Flap migrates |

Harvesting BEM from a machine requires the circuit NFT to still be owned by the treasury.

## Reading state

The contract does not store one progress bar. The page reads the queue and the ledger through these view functions.

| Function | Contents |
|---|---|
| `queue` | Kits ready, next to arm, next to start, live count |
| `snapshot` | Token, Dividend, treasury BNB, parts, machine count, `totalShares`, floor, sitting `$BEM` |
| `machine` / `machines` | Whether a given machine can arm, can start, is live |

Anyone can continue in this order: start if a window is open, else arm, wait one block, tape-out if parts remain, then the executor buys if BNB remains. Poke order: [Contracts](/contracts).
