> For the complete documentation index, see [llms.txt](https://docs.tonadocash.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tonadocash.com/protocol-reference/treasury-router.md).

# TreasuryRouter & buyback flywheel

`TreasuryRouter` is the protocol's revenue-handling contract. It accumulates protocol fees from the pool contracts, swaps them to TONADO via STON.fi v2, and distributes the bought TONADO between **burn** (deflationary supply reduction) and **veTONADO stakers** (real yield).

## Why a separate contract

Three reasons:

1. **Anonymity-set isolation.** The pool's deposit handler routes fees to the treasury at deposit time. The pool itself stays denomination-aware and uniform-per-user. The treasury accumulates across all pools without leaking which user paid what fee.
2. **Governance flexibility.** Swap recipes (STON.fi message bodies) change rarely but vary by trading venue. Keeping them in dict storage that governance can `AdminAddSwap` / `AdminRemoveSwap` means we don't need a contract upgrade if STON.fi ships a v2.1 with different message format.
3. **Permissionless triggers.** Anyone can call `TriggerSwap(swapId)` on a registered recipe (subject to a per-recipe cooldown). The protocol doesn't depend on governance attention for the buyback to fire. Same for `Distribute` (burn + stake split).

## Money flow

```
                                                                            ┌─────────────────────────┐
                  ┌─────────────────────┐                                   │ TONADO master           │
        deposit   │ Pool (native        │                                   │  ← burn                 │
       ─────────▶ │  or jetton)         │                                   └──┬──────────────────────┘
                  └──────────┬──────────┘                                      │ TEP-74 burn op
                             │ protocolFee in TON or jettons                   │ ┌────────────────┐
                             ▼                                                 │ │                │
                  ┌─────────────────────┐                                      │ │ totalSupply −= │
                  │ TreasuryRouter      │                                      │ │ amount         │
                  │  accumulates        │                                      │ └────────────────┘
                  └──────────┬──────────┘                                      │
                             │                                                 │
                  ┌──────────┴───────────────┐                                 │
                  │ governance whitelists    │                                 │
                  │ swap recipe              │                                 │
                  │ (AdminAddSwap)           │                                 │
                  └──────────┬───────────────┘                                 │
                             ▼                                                 │
              ┌─────────────────────────────┐                                  │
              │ TriggerSwap (permissionless,│                                  │
              │  cooldown-gated)            │                                  │
              └──────────┬──────────────────┘                                  │
                         │ outbound TEP-74 transfer (STON.fi swap payload)     │
                         ▼                                                     │
              ┌─────────────────────────────┐                                  │
              │ STON.fi v2 router → pool    │                                  │
              └──────────┬──────────────────┘                                  │
                         │ bought TONADO routes back via TEP-74                │
                         ▼                                                     │
                  ┌─────────────────────┐                                      │
                  │ Treasury's TONADO   │                                      │
                  │ wallet → transfer_  │                                      │
                  │ notification        │                                      │
                  └──────────┬──────────┘                                      │
                             │ credits pendingDistribute                       │
                             ▼                                                 │
                  ┌─────────────────────┐                                      │
                  │ TreasuryRouter      │                                      │
                  │  pendingDistribute  │                                      │
                  └──────────┬──────────┘                                      │
                             │                                                 │
              ┌──────────────┴──────────────┐                                  │
              │ Distribute (permissionless) │                                  │
              └──────────┬─────────┬────────┘                                  │
                         │         │                                           │
       50% burn ◀────────┘         └────────▶ 50% to veTONADO StakingRewards   │
                         │                              │                      │
                         ▼                              ▼                      │
              (TEP-74 burn message)     (TEP-74 transfer → veTONADO            │
                         │               sees transfer_notification →         │
                         │               increments rewardPerVoteAcc;          │
                         │               stakers claim via ClaimRewards)       │
                         └────────────────────────────────────────────────────▶
```

## Swap recipe model

Swap recipes are pre-approved by governance. Each recipe stores:

* `dest` - the outbound destination (typically the treasury's own jetton wallet of the IN asset for a STON.fi jetton-to-jetton swap)
* `attachedValue` - TON to attach to the outbound (covers swap pool gas + forward fees; STON.fi recommends \~0.3 TON for cross-pool swaps)
* `cooldownSeconds` - minimum interval between triggers
* `lastTriggeredAt` - bookkeeping
* `body` - the actual STON.fi swap cell (built off-chain via [`stonfiV2.ts`](https://github.com/tonadocash/monorepo/blob/main/packages/core/src/stonfiV2.ts) helpers)

Lifecycle:

| Op                                                  | Auth   | Effect                            |
| --------------------------------------------------- | ------ | --------------------------------- |
| `AdminAddSwap(swapId, dest, value, cooldown, body)` | owner  | Register recipe                   |
| `AdminRemoveSwap(swapId)`                           | owner  | Decommission recipe               |
| `TriggerSwap(swapId)`                               | anyone | Fire recipe (subject to cooldown) |

This is intentionally narrow. Governance encodes the swap message off-chain using the SDK helpers in [`stonfiV2.ts`](https://github.com/tonadocash/monorepo/blob/main/packages/core/src/stonfiV2.ts); the contract just ships the bytes. If STON.fi changes message format, the fix is `AdminRemoveSwap` + `AdminAddSwap` with the new body - no contract upgrade.

## Burn split

The `burnSplitBps` parameter controls the deflationary vs yield mix:

* `0` - 100% to veTONADO stakers. Pure real yield, no supply reduction.
* `5000` - 50/50 (default). Half burned, half yields.
* `10000` - 100% burned. Pure deflation, no staker yield.

Governance can tune via `AdminSetBurnSplit` up to `MAX_BPS = 10000`.

## Permissionless `Distribute`

`Distribute` reads `pendingDistribute`, splits it into burn + stake amounts, and ships them. Anyone can call. If `pendingDistribute == 0` or `stakingRewards` is unset (when split needs it), the op reverts.

This permissionless trigger means the buyback flywheel turns automatically as long as somebody (anybody) pays gas to call `TriggerSwap` and then `Distribute`. The protocol doesn't depend on governance keeping a cron job running.

## Files

* [`treasury_router.tolk`](https://github.com/tonadocash/monorepo/blob/main/apps/contracts/contracts/treasury/treasury_router.tolk)
* [`treasuryRouter.ts`](https://github.com/tonadocash/monorepo/blob/main/packages/core/src/treasuryRouter.ts)
* [`stonfiV2.ts`](https://github.com/tonadocash/monorepo/blob/main/packages/core/src/stonfiV2.ts) - STON.fi v2 swap-cell builders
* [`p2-treasury.test.ts`](https://github.com/tonadocash/monorepo/blob/main/apps/contracts/tests/p2-treasury.test.ts) - 21 sandbox tests
* [`deploy-treasury-router.ts`](https://github.com/tonadocash/monorepo/blob/main/apps/contracts/scripts/deploy-treasury-router.ts) - single-contract deploy + bind script

## See also

* [tokenomics.md](/protocol-reference/tokenomics.md) - broader picture
* [contracts-spec.md](/protocol-reference/contracts-spec.md) - surface area
* [../operations/pool-deployment.md](/operations/pool-deployment.md) - operator runbook covering pool deployment + buyback bootstrap
