Appearance
Swap Pipeline
Every trade in the protocol follows a multi-phase execution pipeline. Each phase depends on outputs from prior phases, and the entire sequence executes atomically - if any phase fails, no state changes are committed.
Pipeline Phases
1. Bucket Tick
Before any trade logic begins, the market's exposure buckets are advanced to the current time. Expired buckets are cleared and their aggregates subtracted from market totals. This ensures all subsequent calculations use fresh state.
2. Position Allocation
The protocol finds the trader's existing position for this market (if any) or allocates a new slot in their margin account. Each margin account supports up to 16 concurrent positions across different markets.
3. End-Time Validation
The requested position expiry is validated: it must be in the future, aligned to a bucket boundary, and within the market's valid window range (see Markets & Rolling Windows).
4. Pre-Swap Settlement and Health Check
Before the trade executes, all pending funding is settled on the trader's position (applying any accumulated floating rate payments since the last touch). For risk-increasing trades, the account's health must be non-negative before the trade - you cannot increase risk from an already-unhealthy position.
5. Risk Classification
The trade is classified based on how it changes the trader's risk profile:
- Delta OI: Change in absolute notional (are they increasing or decreasing their position size?)
- Delta DV01: Change in dollar-value-of-a-basis-point (accounting for tenor)
- Risk direction: If either OI or DV01 increases, the trade is risk-increasing. Otherwise it is risk-reducing.
- Pool exposure direction: Does this trade increase or decrease the pool's net directional exposure?
This classification determines which safeguards apply to the trade (deviation checks, cap enforcement, margin requirements) and which fee multiplier is used. Note that because each position has a fixed expiry set at open time, a trader cannot change a position's tenor, so the theoretical edge case where OI decreases while DV01 increases (by shifting to a longer tenor) cannot arise within a single position.
6. Effective Depth and Segment Allocation
The liquidity depth available for the trade depends on its risk direction:
- Risk-increasing trades use a risk budget -- the allocated depth minus the DV01 reserve and any utilization-based reduction. This protects LPs by limiting how much additional risk can be taken.
- Risk-reducing trades use the full allocated depth, ensuring traders can always exit at reasonable prices regardless of current utilization.
The effective depth is then distributed across the 7 tenor segments using configurable segment weights, and a boundary-safe effective depth is computed for the exact traded tenor by blending the depths of the two neighboring segments (see Curve Engine & Execution).
7. Pre-Trade Mark at Tenor
The engine identifies the two knots bracketing the chosen tenor, advances their Mark TWAP integrals, and interpolates the pre-trade mark rate. This mark is used for both deviation checks (step 10) and fee deviation component calculation.
8. Pricing Notional and Mid-Rate
The trader's face notional is converted to a pricing notional (carry-equivalent exposure proportional to DV01) by multiplying by the tenor's year-fraction. The mid-rate at the traded tenor is computed by interpolating the curve's integrated funding values between the two bracketing knots.
9. Impact Kernel Execution
The pricing notional executes through the stateless 3-tranche Impact Kernel (see Curve Engine & Execution). The kernel uses the mid-rate as the starting point, the effective depth at the tenor, and the trade direction to produce two outputs:
- Execution VWAP -- the volume-weighted average rate across the trade path. This becomes the position's entry rate.
- Endpoint rate -- the post-trade marginal rate. This is recorded in the per-knot Mark TWAP.
After execution, the curve is updated via a normalized 2-knot push: only the two bracketing knots are moved, with optional smoothing applied to interior knots.
10. Mark Deviation Check
For risk-increasing trades, both the execution VWAP and the endpoint rate must fall within the mark TWAP's deviation band. If either is out of bounds, the trade is rejected. This prevents large trades from moving the rate too far from recent consensus.
Risk-reducing trades skip this check - exits are always allowed.
11. Dynamic Fees
The fee pipeline computes the total fee from multiple components (see Fees):
- Sum the additive components: base + utilization + deviation + staleness + inventory + volatility
- Apply the asymmetric multiplier (higher for risk-increasing, lower for risk-reducing)
- Cap at the configured maximum
- Compute the fee amount based on carry-sized notional
The fee is deducted from the position's realized PnL and split between LP fees and protocol fees.
12. Cap Enforcement
For risk-increasing trades, the post-trade OI and DV01 are checked against market-level and pool-level caps (see Risk & Limits). If any cap would be breached, the trade is rejected.
Risk-reducing trades bypass cap enforcement - you can always reduce risk even if the market is at capacity.
13. State Mutation
If all checks pass, the trade is committed atomically. Position notional, entry rate, and timestamps are updated. Market aggregate OI, DV01, and pool net notional are adjusted to reflect the new exposure. Bucket-level exposure is updated for the position's expiry bucket. Fee accumulators are credited with the LP and protocol shares. And if this trade qualifies as the bucket's largest-wins candidate, the mark TWAP observation is updated.
14. Post-Swap Health Check
For risk-increasing trades, the account's health is verified one final time after all state changes. The account must satisfy both:
- Maintenance margin: Health must be non-negative
- Initial margin: Equity must exceed the initial margin requirement
If the post-trade account doesn't meet these requirements, the entire transaction reverts.
Risk-Reducing Bypass
A recurring theme across the pipeline is that risk-reducing trades receive favorable treatment at every stage:
| Check | Risk-Increasing | Risk-Reducing |
|---|---|---|
| Pre-trade health | Required | Skipped |
| Deviation band | Enforced | Skipped |
| Cap enforcement | Enforced | Skipped |
| Post-trade margin | Required (IM) | Skipped |
| Fee multiplier | Higher (taker) | Lower (maker) |
| Depth available | Risk budget only | Full depth |
This asymmetry ensures traders can always exit or reduce positions - even in adverse market conditions. The protocol prioritizes allowing risk reduction because blocking exits could lead to cascading liquidations and systemic risk.