Skip to content

Economic — Market Rates & the 777 Floor

TL;DR: YUE's internal rate formula is linear above Mod = 777 and gets penalizingly non-linear below it. Swap through asset chains whose Mod stays comfortably above 777.

Why this matters

YUE has an internal swap primitive — Hong (buy a QING asset) and Hung (redeem a QING asset) — with a rate function that you won't find in any AMM textbook. It's a piecewise function keyed on a value called Mod, and it goes sharply against you when Mod drops below 777.

If you plan internal swaps without checking Mod, you can take surprise 10×–1000× slippage.

The numbers

From YUE.GetAssetRate:

Mod = AssetRate / (10 ** (decimals - 2))

if Mod < 777:
    Rate = Rate / ((777 - Mod) * 10 ** (decimals - 5))
# else: Rate is linear (unchanged before the if-check)
Term Meaning
AssetRate Rate read through the QING chain via GetMarketRate on the parent asset.
decimals The asset's decimals (usually 18).
Mod AssetRate scaled down to a comparable magnitude for the threshold check.
777 The floor. Below this, the piecewise branch activates.
(777 - Mod) Grows as Mod shrinks — denominator increases, so rate decreases.
10 ** (decimals - 5) Additional scaling factor in the penalty denominator.

The piecewise formula means that at Mod = 776 the denominator is 1 * 10^13 (for 18-dec); at Mod = 700, it's 77 * 10^13. Each unit drop in Mod below 777 adds 10^(decimals - 5) to the denominator.

Source: YUE.

The play

  1. Always read GetAssetRate(Spend, Receive) before a swap. If the rate looks crazy low, you probably tripped the Mod < 777 branch.
  2. Pick pairs whose asset chain rates sit comfortably above 777. Newly launched tokens with low MarketRate often have Mod < 777; established tokens usually don't.
  3. (inferred) Swap in one direction at a time, not back-and-forth. Every Hong/Hung writes Hypobar/Epibar on your YUE per-QING. If that counter is what a future strategy reads, cycling leaves a bigger bar trail than you might want.
  4. Use IsValidAsset to check chain first. YUE.IsValidAsset traverses the QING chain until it finds the Integrative asset. If that traversal fails, your swap reverts, wasting gas.
  5. Chain-aware swaps. If you're swapping A → C and there's no direct rate, YUE walks the QING chain from A toward C, multiplying rates at each hop. The Mod < 777 penalty applies at each hop independently — a long chain with one weak link can tank the composite rate.

Worked example

Suppose you have 1000 units of asset A (18-dec) and want to convert to asset C via a 2-hop QING chain (A → B → C).

  • Hop 1: AssetRate(A, B) = 800 * 10^16. Mod = 800. 800 ≥ 777, no penalty. Rate unchanged.
  • Hop 2: AssetRate(B, C) = 776 * 10^16. Mod = 776. Penalty fires. Rate / ((777-776) * 10^13) = Rate / 10^13.

If the raw hop-2 rate was 1 * 10^18, the penalized rate is 1 * 10^5. You just lost 13 orders of magnitude on that hop.

Remedy: find a different path where both hops sit above 777, even if the "nominal" rate is lower.

Gotchas

  • decimals varies. The formula uses the token's declared decimals. For 6-dec tokens (rare in this ecosystem), 10 ** (decimals - 5) = 10, and the penalty per unit is much smaller. Don't assume 18-dec everywhere.
  • No slippage protection built into Hong/Hung directly. Unlike Uniswap, YUE doesn't take a minOut param — you compute the rate, then call the swap; the rate can change between calls if someone else mutates the market rate. Racing is a risk on newly listed tokens.
  • ExchangeRateNotFound reverts you, saving gas; InvalidPair means the asset chain doesn't terminate at the Integrative you requested. Handle both.
  • Hypobar / Epibar accumulate per-QING on React. Calling React(Qing) bumps those counters; Hong/Hung do not (they call Purchase/Redeem). If you want "bar bumps" for a strategy that reads them, explicitly React.
  • (inferred) Rate-modifier abuse is not clearly a thing. Bouncers can't set AssetRate directly; it's sourced upstream. But if you're the owner of a token in the chain, you can AddMarketRate and nudge the magnitude.

Where it cross-connects