# Protocol fees & productive-work distribution

> Runs at **block seal** (not while paused). Pause and Bitcoin anchor stay separate launch steps.

## Governance (simple)

1. **Genesis** — founder publishes **KIP-0001** (this split). Active from block 0.  
2. **Later** — draft a KIP (BIP-style page: [`/l2-proposals`](/l2-proposals) / `/kip`).  
3. **Vote** (UI later) → **approve** + set `activate_at_block`.  
4. From that height, every validator uses the new policy. No drama.

Admin schedule (when ready): `POST /l2/proposals/admin/schedule-fee`  
Migration: `014_l2_proposals.sql`

## Fee taxonomy (never mix)

| Kind | Where it goes | Who benefits |
|------|---------------|--------------|
| **Gas** (eternal **1 KRAY**) | Treasury (`gas_fee` / `creditTreasuryFee`) | Protocol fee pool |
| **App fee** (AI mint, etc.) | Treasury (`amount` → Treasury) | Same pool |
| **AMM LP fee** (0.3%) | Stays in `POOL_ESCROW_DOG_KRAY` (etc.) | LPs via reserves |
| **Social / Dev escrow** | Named buckets / chosen addresses | Escrow claimants — **not** this splitter |

Pool escrow DOG/KRAY is healthy as-is: swap fee compounds into the pool; swap **gas** is still 1 KRAY to Treasury.

## Seal-time split (KIP-0001 — Era dos Guardiões)

Full game theory: [`FEE_CONSTITUTION.md`](./FEE_CONSTITUTION.md)

| Bucket | Share | Recipients |
|--------|-------|------------|
| Treasury retain | 40% | Protocol reserve / Phase B |
| **26 Guardians** | **30%** | **Equal 1/26** per RuneSpace NFT owner |
| Social ranking | 15% | Top inscription / L2 NFT profiles |
| User ranking | 15% | Top wallet profiles (engagement) |

- `min_pool`: 26 KRAY — below that, retain all.
- Integers only; unresolved guardian slots → Treasury (never mint).
- Leaves: `guardian_reward` (× up to 26), `fee_share_social`, `fee_share_builder`.

## Anti-bug rules

1. Only debit Treasury for fees already collected in the claimed block.  
2. Idempotent: if reward TXs exist for `batch_id`, do not pay again.  
3. Stuck `executing` → CRITICAL alert, no auto re-credit.  
4. Social/builders derived **from the block’s own TXs** (deterministic at seal).

## Preview (safe while paused)

```http
GET /l2/blocks/admin/fee-distribution-preview
```

## Ranking (long-horizon) vs fee share (per block)

- **Leaderboards** (`WEIGHTS` v2 in `inscription-social.js`): paid likes/boosts outweigh free follows.  
- **Fee shares**: who paid gas / whose assets moved **in that block**.

Together = Proof of Productive Work without turning the L2 into a farm.
