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

# Pricing and fees

> How MultiliquidSwap prices a leg at NAV, which fees apply to each route, and who pays them.

Multiliquid prices every leg from the USD value of its assets and the capital provider's fee schedule. There is no pool and no price impact: a leg's price changes only when a price, a fee, or, for \$TSY, the user's yield changes. `quoteSwap` and `swap` run the same calculation.

## How a leg is priced

**1. Normalize**

The fixed amount is scaled to 18 decimals. For a \$TSY input settled by the \$TSY delegate, it is first converted to its yield-adjusted value.

**2. Value in the route unit**

The amount is converted to the route unit, the stablecoin whose capital provider settles the leg, using each asset's USD price: an RWA's from its price adapter, and a stablecoin's from its configured USD value.

**3. Charge the protocol fee**

The protocol fee is calculated on the route value and reported separately. It is not deducted from what the receiver gets.

**4. Apply the capital provider's fees**

Each fee leg deducts the capital provider's discount or fee and the protocol's spread fee from the route value.

**5. Convert to the output**

The remaining value is converted to the output asset and its decimals.

An exact-out leg runs the same steps in reverse, from the fixed output to the input it requires.

## Fees

| Fee | Reported as | Rate set by | Paid by | Paid to |
| - | - | - | - | - |
| Protocol fee | `issuerFeeAmt` | Multiliquid, per stablecoin registration | The capital provider | The Multiliquid vault |
| Spread fee | `spreadFeeAmt` | Multiliquid, as a share of the capital provider's spread | The user | The Multiliquid vault |
| RWA redemption fee | `lpFeeAmt` | The capital provider, per RWA | The user | The capital provider's stablecoin custody |
| Stablecoin acceptance or redemption fee | `lpFeeAmt` | The capital provider, per counterparty stablecoin | The user | The capital provider's stablecoin custody |
| RWA discount | Not reported | The capital provider, per RWA | The user | Kept by the capital provider, which pays out less |

Fees the user pays reduce an exact-in leg's output, or raise an exact-out leg's input. The protocol fee does neither: the capital provider pays it from its side of the settlement. All three reported fees are in the fee stablecoin's units, rounded up. A registration that Multiliquid marks as exempt pays neither the protocol fee nor the spread fee.

## Fees by route

| Route | Route unit and fee stablecoin | Fee legs applied | `lpFeeAmt` |
| - | - | - | - |
| Stablecoin to RWA | The input stablecoin | The RWA's redemption fee | The redemption fee |
| RWA to stablecoin | The output stablecoin | The RWA's discount | Zero |
| RWA to RWA | The `stablecoinDelegateID` stablecoin | The input RWA's discount, then the output RWA's redemption fee | The redemption fee |
| Stablecoin to stablecoin, output-side delegate | The output stablecoin | The acceptance fee for the input stablecoin | The acceptance fee |
| Stablecoin to stablecoin, input-side delegate | The input stablecoin | The redemption fee for the output stablecoin | The redemption fee |

Every fee leg also charges a spread fee. Prefunded routes price like their base routes.

## The spread fee

The capital provider's spread for an asset is the gap between what it pays for the asset and what it charges to deliver it, from its two settings for that asset:

```text theme={null}
spread      = 1 / (1 - redemptionFee) - (1 - discount)
spreadRate  = max(spread × spreadProtocolTakeRate, 0.0001)
```

* For an RWA, `discount` is the RWA discount and `redemptionFee` the RWA redemption fee.
* For a counterparty stablecoin, `discount` is the acceptance fee and `redemptionFee` the redemption fee.
* `spreadProtocolTakeRate` is one global rate set by Multiliquid.
* The rate never falls below 1 basis point, unless the registration is exempt.

Both settings shape the spread fee on every leg, even though each leg deducts only one of them.

## Worked example

A user sells 500 RWA tokens priced at \$2.00 to a capital provider's USDC delegate, exact-in. The capital provider sets a 10% discount and a 20% redemption fee on that RWA. Multiliquid takes 5% of the spread and charges the capital provider a 10 basis point protocol fee.

| Step | Calculation | Amount |
| - | - | -: |
| Route value | 500 × \$2.00 | \$1,000.00 |
| Protocol fee | 0.10% of \$1,000.00 | \$1.00 |
| Discount | 10% of \$1,000.00 | \$100.00 |
| Spread | 1 / (1 − 0.20) − (1 − 0.10) = 0.35 | |
| Spread fee | 0.35 × 5% = 1.75% of \$1,000.00 | \$17.50 |
| User receives | \$1,000.00 − \$100.00 − \$17.50 | \$882.50 |
| Multiliquid vault receives | \$1.00 + \$17.50 | \$18.50 |
| Capital provider pays out | \$882.50 + \$18.50 | \$901.00 |

The quote reports `tokenOutAmt` of 882.50 USDC, `issuerFeeAmt` of 1.00, `spreadFeeAmt` of 17.50, and `lpFeeAmt` of zero, all in USDC base units. The 20% redemption fee is not charged on this leg; it only widens the spread.

## Rounding

| Quantity | Rounds |
| - | - |
| Exact-in output | Down, so the receiver never gets more than the input covers |
| Exact-out input | Up, so the input always covers the fixed output |
| Protocol and spread fees | Up |
| RWA redemption fees | Up |
| Stablecoin acceptance and redemption fees | Down on an exact-in leg, up on an exact-out leg |
| RWA discounts | Down |

Reported fee amounts are then rounded up to the fee stablecoin's decimals.

An exact-out leg grosses the target up by each fee leg in reverse, and adds one unit of rounding buffer where rounded fees would otherwise leave it one unit short.

## Decimals and prices

* **Tokens** may have up to 18 decimals. Amounts are scaled to 18 decimals for the calculation and back at the end.
* **Prices** are USD values with 18 decimals: `1e18` is \$1.00. An RWA's price comes from its [price adapter](https://docs.multiliquid.xyz/evm/contracts/price-adapters.md), and a zero price reverts.
* **Stablecoins** are valued at the USD value Multiliquid configures for each registration, optionally checked against an oracle by a [guardrail](https://docs.multiliquid.xyz/evm/contracts/price-adapters.md#stablecoin-guardrails).
* **Rates** are fractions with 18 decimals: `1e16` is 1%, `1e14` is 1 basis point.

## \$TSY inputs

When the \$TSY delegate settles a leg whose input is \$TSY, the input is valued by the user's yield, not at face value:

* **Withheld credits first.** Credits from recent deposits that have not yet merged into the user's main credits, which takes at least 24 hours, count at face value.
* **Then main credits** count at the user's yield multiplier.
* **Partial days.** A swap to a stablecoin also earns the part of the current day since the last posted rate, at that rate, up to a limit Multiliquid sets. A swap to an RWA earns whole days only.
* **Fees are paid in new \$TSY.** The delegate burns exactly the user's input, and mints the protocol and capital provider fees as new \$TSY instead of taking them out of the input.

`swap` accrues the user's interest before pricing, while `quoteSwap` uses the stored state. [Treasury contracts](https://docs.multiliquid.xyz/evm/contracts/treasury.md#yield-accounting) describes credits and the multiplier.

## Next steps

> [card] [Stablecoin delegates](https://docs.multiliquid.xyz/evm/contracts/stablecoin-delegate.md)
>
> How each delegate moves the input, the output, and the fees.

> [card] [Price adapters](https://docs.multiliquid.xyz/evm/contracts/price-adapters.md)
>
> Where each USD price comes from.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.