> ## Documentation Index
> Fetch the complete documentation index at: https://docs.darknyx.trade/llms.txt
> Use this file to discover all available pages before exploring further.

> How trading fees work on Darknyx, a basis-point protocol fee both sides pay, collected as notes at settlement and pre-funded by each order's collateral.

# Fee structure

# Fee Structure

<Info>
  **TL;DR**

  Darknyx charges a flat **protocol fee** in basis points (for example, 30 bps). **Both
  sides of a trade pay their own fee.** Each order pre-funds its fee as part of its
  collateral, and the fee is collected at settlement as a **fee note** minted to the
  protocol, so fees, like everything else, settle privately on-chain.
</Info>

## The fee model

Each side pays in the asset it contributes to the trade. In raw protocol units:

```text theme={null}
quote_amount = floor(base_amount × clearing_price / price_scale)
buyer fee    = floor(quote_amount × fee_rate_bps / 10_000)  // quote asset
seller fee   = floor(base_amount  × fee_rate_bps / 10_000)  // base asset
```

Two principles define how it is applied:

* **Both legs pay.** The bid and the ask each pay a fee on their own side of the
  trade. There is no maker rebate or taker surcharge, because a batch auction has
  no maker/taker roles (see [Clearing Price](../trading-concepts/clearing-price.mdx)).
* **The fee is pre-funded.** An order must reserve enough note value to cover
  *both* its nominal cost *and* its own fee. The required collateral is:

```text theme={null}
required collateral = nominal cost + fee
```

For a bid, the worst-case nominal quote cost is
`floor(amount × price_limit / price_scale)`; for an ask it is the base `amount`.
The engine derives the applicable floor-rounded fee at intake. If an order's
collateral note does not cover both, the order is rejected rather than allowed
to under-pay.

<Info>
  **Collateral must include the fee**

  Read the finalized market and vault configuration when selecting a collateral
  note. The order request carries the note's actual amount; intake recomputes its
  commitment and rejects a note that cannot cover the worst-case nominal amount
  plus fee. Higher-level wallet software can automate that coin selection, but the
  wire-level SDK does not add value to an existing note.
</Info>

## How fees are collected

Fees are collected **at settlement**, in the same atomic, proven step as the rest
of the trade. When a batch settles, the output notes include the protocol's **fee
notes**, one per asset side, minted alongside the traded asset and any change
note. There is no separate fee transaction and no off-chain fee accounting: the
fee moves as a note, on-chain, under the same zero-knowledge proof that gates the
trade.

```text theme={null}
settle a match ──► outputs:
                     • counterparty's filled asset
                     • your change note (unfilled remainder)
                     • fee note (base side)   → protocol
                     • fee note (quote side)  → protocol
```

Because the fee is charged on the actual cleared amount, an order that locked
fee-inclusive collateral on its worst-case limit and then fills at a better
clearing price gets unused collateral back as part of its change note.

## Fee-note privacy and recovery

Fee notes must be recoverable by the protocol without becoming a public clue to
which deposited note traded. Their private inner value therefore incorporates
a rotating **fee epoch key** together with the consumed note's unlinkable use
tag and the fee side. The settlement proof binds the key's governed on-chain
commitment and epoch without revealing the key itself.

This prevents an observer from trying every plausible small fee amount and
matching the resulting public fee commitment back to a historical input leaf.
For durability, each verified batch also records a fixed-size encrypted fee
recovery bundle. Historical epoch keys let the protocol reconstruct only the
fee notes that actually settled on finalized chain; users do not manage these
keys or bundles.

## Worked example

Suppose the fee rate is 30 bps (0.30%) and you place a bid to buy `10` base at a
limit of `150` quote each. Expressed here in human units for readability:

```text theme={null}
nominal cost   = 10 × 150        = 1500 quote
fee            = 1500 × 30 / 10_000 = 4.5 quote
collateral     = 1500 + 4.5      = 1504.5 quote   ← what your note must cover
```

If the batch clears at `148`, you pay `1480` for the fill, your fee is charged on
the cleared amount, and the difference comes back to you as a change note, all in
one settled, proven step. On-chain arithmetic uses smallest token units and the
configured `price_scale`, with every division rounded down as shown above.

## Why fees settle as notes

Collecting fees as on-chain notes keeps the whole system consistent: there is one
value-movement mechanism (notes, gated by proofs), one place aggregate
liabilities are visible (the public
[transparency](/api-reference/settlement/transparency) reserves, which account
for every mint including the protocol's), and no privileged off-chain ledger.
Individual fee amounts and their input lineage remain shielded while the proof
still enforces the exact configured fee.
