How pricing works
All prices are E8 (USD per whole token × 1e8); USD amounts are E6. Let mid be the oracle price for the market's perp index.
inv = tokenBalance − targetInventory // signed, token units
invUsd = inv × mid
dir = +1 when you SELL token to the pool (inventory rises)
−1 when you BUY token from the pool (inventory falls)
invAfter = invUsd + dir × tradeUsd
revert InventoryLimit if |invAfter| > maxInventoryUsdE6
revert TradeTooLarge if tradeUsd > maxTradeUsdE6
pressure = clamp(dir × invAfter / maxInventoryUsdE6, 0, 1)
spreadBps = min(baseSpreadBps + skewSpreadBps × pressure, maxSpreadBps)
Only the side that pushes inventory away from target gets widened; the side that brings it back trades at the base spread. Then:
| Direction | Formula |
|---|---|
| Buy token with USDC (e.g. USDC → UBTC) | amountOut = usdcIn / (mid × (1 + spread)) |
| Sell token for USDC (e.g. WHYPE → USDC) | amountOut = tokenIn × mid × (1 − spread) |
Protocol fee: protocolFeeUsdE6 = tradeUsd × spreadBps × protocolShareBps / 1e8 is book-kept inside the pool as protocolFeesAccrued (excluded from NAV) until anyone calls claimProtocolFees(). The remaining spread stays in NAV for LPs.
Parameters are set per market (the Markets page shows the live values). WHYPE launched with base 8 bps, skew 40 bps, max 150 bps, inventory cap ±$25,000, per-trade cap $5,000. swapExactIn additionally enforces minAmountOut (your slippage) and deadline.
Oracle
TangentOracle routes between two sources per perp index:
- Posted — the hedger posts Hyperliquid mark prices (
post(perpIndex[], pxE8[], hlTimestampMs[])) every ~15 s or whenever the mark moves more than 5 bps. Stale aftermaxAgeSec(default 45 s). - Native — optional on-chain source (today the Precompilisium
markPxshim; later the Elysium native precompile). Preferred when live and sane.
If both are fresh and disagree by more than maxDeviationBps (default 1%), getPrice reverts PriceDisagreement and the pool fails closed: no quotes, no swaps, until the sources converge. If the posted price is stale and no native source is live, it reverts StalePrice.