04/The desk

Pricing the arbitrage tax

The quant model in packages/quant-kernel/src/microstructure.ts turns market data into a toxicity score, a regime and an EV-ranked range plan, built on the Milionis et al. (2022) result that a constant-product LP loses σ²/8 of pool value per unit time to arbitrageurs. That loss is called LVR, loss-versus-rebalancing. Parity stays out of the pool whenever the fee yield is below it.

Inputs

Each input is a field of MarketSnapshot, filled by collectMarketContext in apps/agent/src/feeds.ts with a provenance label you can see in /status.

FieldSourceIf unavailable
saucerSwapPriceSaucerSwap V2 pool mid from sqrtPriceX96The cycle stops: no price, no decision
referencePriceMedian of Kraken last close and CoinGeckoFalls back to the pool mid
recentLogReturnsKraken HBARUSD 5-minute closes, last 24 hours (288 returns)Empty: volatility uses a 25% prior
orderFlowImbalanceKraken 5-minute signed volume, last hour (12 candles)0
projected24hFeeAprBps24h volume × fee tier / TVL × 365, from SaucerSwap hourly data0, so the desk will not LP
positionNotionalUsdDesk HBAR and USDC from the Mirror Node, at the pool mid0 when no operator account is set
bonzoCollateralUsdNot integratedAlways 0
estimatedGasUsdA fixed $0.05 per swapn/a

EWMA volatility

computeEwmaVolatilityPct is the RiskMetrics estimator with λ = 0.94. The variance starts at the first squared return and each later return updates it as λ·var + (1 − λ)·r². It is annualised with the number of sampling periods in a year, which for 5-minute samples is 105,120. With no returns at all it returns 25%.

Toxicity score and regime

scorePoolToxicity adds three capped parts into a score from 0 to 100:

scorePoolToxicityts
volatility  = min(40, vol% / 150 × 40)          // 150% annualised fills it
skew        = min(35, crossVenueSkewBps / 80 × 35)  // |pool − reference| / reference
flow        = min(25, |orderFlowImbalance| × 25)
score       = volatility + skew + flow

Order-flow imbalance is the volume-weighted tick rule: the sum of sign(return) × volume over the sum of volume, so it runs from −1 to 1 and a value near ±1 means one-sided flow. The regime is TOXIC from 65, ELEVATED from 35, and CALM below that.

Quote fieldFormulaRange
recommendedDynamicFeeBps5 + score / 100 × 95, rounded (the hook's curve)5 to 100 bps
maxSafeSlippageBps15 + 0.45 × score, rounded15 to 75 bps
recommendedSplitCount4 if score ≥ 65, 2 if ≥ 35, else 11, 2 or 4
recommendedTickHalfWidthThe width with the best net EV (below)60 to 3840 ticks

LVR and the LP edge

With σ the annualised volatility, the daily LVR rate is σ² / 365 / 8 and the daily fee rate is the fee APR / 365. The plan reports the difference as lpEdgeDailyPct. When it is zero or negative, providing liquidity loses to arbitrageurs and the plan says so in its rationale: "providing liquidity loses to arbitrageurs, stay out".

estimatePositionLvrUsd estimates the current position's 24-hour LVR as the streaming part, σ²/365/8 × notional × concentration × P(in range), plus a one-off part for a standing price gap d between the pool and the reference, d²/8 × notional × concentration. It is 0 when the position is out of range.

The range optimiser

evaluateRangeCandidates scores 7 symmetric half-widths, all multiples of SaucerSwap's 60-tick spacing: 60, 120, 240, 480, 960, 1920, 3840 ticks. For a half-width w:

evaluateRangeCandidatests
r             = 1.0001^w
concentration = min(400, 1 / (1 − r^−½))         // vs a full-range position
P(in range)   = 2·Φ(w·ln 1.0001 / σ_day) − 1      // driftless, over 24 h
fees          = notional × feeDaily × concentration × P
lvr           = notional × lvrDaily × concentration × P
churn         = (1 − P) × (gas + notional × 0.5 × maxSafeSlippage)
netEV         = fees − lvr − churn

Concentration multiplies fees and LVR alike, so a narrower range only wins if fees beat LVR to begin with and the extra churn of falling out of range does not eat the gain.

From plan to action

buildRebalancePlan picks one of three actions, in this order:

  • DELTA_HEDGE when the inventory is at least 12% off 50/50, the regime is TOXIC or the LP edge is not positive, and the value of hedging beats its friction. The value is the one-day 95% value at risk removed (size × σ_day × 1.645) at a 50% weight. The swap is half the imbalance.
  • HOLD (stay out) when the LP edge is zero or negative.
  • REBALANCE_RANGE when the best width beats the current one by more than the friction (gas plus a quarter of the notional at the safe slippage, or half if out of range), and the position is out of range, the inventory is off 50/50, or the regime is not TOXIC. Otherwise HOLD.

What a rebalance does today

The executor swaps the inventory toward the 50/50 value split a symmetric range needs. The chosen range is kept as a target in the agent's memory; no SaucerSwap position NFT is minted.