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.
Fees
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
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:- For an RWA,
discountis the RWA discount andredemptionFeethe RWA redemption fee. - For a counterparty stablecoin,
discountis the acceptance fee andredemptionFeethe redemption fee. spreadProtocolTakeRateis one global rate set by Multiliquid.- The rate never falls below 1 basis point, unless the registration is exempt.
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.
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
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:
1e18is $1.00. An RWA’s price comes from its price adapter, 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.
- Rates are fractions with 18 decimals:
1e16is 1%,1e14is 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 describes credits and the multiplier.
Next steps
Stablecoin delegates
How each delegate moves the input, the output, and the fees.
Price adapters
Where each USD price comes from.