Economic — Market Rates & the 777 Floor
TL;DR: YUE’s internal rate formula is linear above
Mod = 777and gets penalizingly non-linear below it. Swap through asset chains whoseModstays comfortably above 777.
Why this matters
Section titled “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
Section titled “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
Section titled “The play”- Always read
GetAssetRate(Spend, Receive)before a swap. If the rate looks crazy low, you probably tripped theMod < 777branch. - 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. - (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.
- Use
IsValidAssetto check chain first. YUE.IsValidAsset traverses the QING chain until it finds the Integrative asset. If that traversal fails, your swap reverts, wasting gas. - Chain-aware swaps. If you’re swapping
A → Cand there’s no direct rate, YUE walks the QING chain from A toward C, multiplying rates at each hop. TheMod < 777penalty applies at each hop independently — a long chain with one weak link can tank the composite rate.
Use these calls here. Simulations preview the current state; each confirmed call is a separate transaction.
YUE.GetAssetRate(address GwatAsset, address Integrative)Read
Open this function to load its call form.
YUE.IsValidAsset(address GwatAsset, address Integrative)Read
Open this function to load its call form.
YUE.Hong(address SpendAsset, address QingAsset, uint256 PurchaseAmount)Simulate / call
Open this function to load its call form.
YUE.Hung(address QingAsset, address ReceiveAsset, uint256 RedeemAmount)Simulate / call
Open this function to load its call form.
Worked example
Section titled “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
Section titled “Gotchas”decimalsvaries. The formula uses the token’s declareddecimals. 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/Hungdirectly. Unlike Uniswap, YUE doesn’t take aminOutparam — 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. ExchangeRateNotFoundreverts you, saving gas;InvalidPairmeans the asset chain doesn’t terminate at the Integrative you requested. Handle both.- Hypobar / Epibar accumulate per-QING on
React. CallingReact(Qing)bumps those counters; Hong/Hung do not (they callPurchase/Redeem). If you want “bar bumps” for a strategy that reads them, explicitlyReact. - (inferred) Rate-modifier abuse is not clearly a thing. Bouncers can’t set
AssetRatedirectly; it’s sourced upstream. But if you’re the owner of a token in the chain, you canAddMarketRateand nudge the magnitude.
Where it cross-connects
Section titled “Where it cross-connects”- Economic: Sinks & Sources — what you’re trying to rotate in and out.
- Economic: Overflow Play — swapping out of H2O/VITUS before they spill.
- Venues: Cover-Charge Tuning — rate implications for QING owners.
- Meta: DSS Bundling — bundling a swap + a chat in one tx.