Pool After-Swap Pipeline
This document specifies the atomic, ordered post-swap updates owned by MarketController (planned, currently implemented directly in swap logic). It ensures market subsystems update consistently with safety and clear degrade rules.
Ordering (MVP)
-
Update market GTWAP oracle
market::Oracle.update(end_tick, timestamp)(impl:OracleState::update())- If GTWAP stale (cardinality/time), fall back to current tick and mark degraded.
-
Compute dynamic fee (post-execution)
- Inputs: start_tick, end_tick, trade_direction, amount_in, PoolState, current_slot
- Output:
fee_bpswithin[MIN_TOTAL_FEE_BPS, MAX_TOTAL_FEE_BPS] - Apply user-provided
max_fee_bpscap (revert if exceeded).
-
Split fees (configurable split)
- Recipients: LP accumulator, PoolReserve, PoolBuffer, Protocol Treasury, Creator (protocol tokens)
- Apply rounding policy: conservative toward protocol solvency on ties.
-
Update FlowSignals (lightweight; MVP)
- Update flow EWMA from swap; optionally incorporate JIT metrics when enabled.
-
JIT v0 (optional; MVP)
- If
enable_jitis true, place a contrarian micro-band (fixed spread, 1-tick range) funded from PoolBuffer, respecting per‑swap/per‑slot budgets and floor guard; execute within the swap and remove unfilled.
- If
-
Floor maintenance (bounded)
- If ratchet cooldown passed, recompute floor via
market::Floor.calculate_floor_tick()and ratchet up if higher. - Enforce
ask_tick >= floor_tick + bufferinvariant for any protocol-owned asks.
- If ratchet cooldown passed, recompute floor via
-
SafetyController observe
- Record metrics (fee bps distribution, volatility, oracle freshness) and enforce degrade actions if thresholds crossed.
Noncritical steps: Event emission and optional metrics updates are best‑effort; failures in these steps must not revert an otherwise valid swap.
Degraded Mode Rules
- GTWAP stale: disable rebates (direction bonuses), raise impact floor to
min_floor_bps, proceed with swaps. - Protocol oracle stale: swaps OK; pause
exit_feelssoluntil healthy. - Excess volatility: widen fee bounds minimally; do not exceed user fee caps.
Required Accounts (per swap)
- Market, vaults, market::Oracle (OracleState), MarketController (planned), MarketReserve (planned), Buffer (τ),
- LP fee accumulators, FlowSignals, market::Floor, SafetyController.
Events (emit)
- FeeSplitApplied, RebateApplied (if any), OracleUpdated (pool),
- FloorRatcheted (if changed), SafetyDegraded/Paused (if actioned).