AMM Mechanism Details
AMM Pricing Formula: The AMM uses a pricing function appropriate for perpetuals. A simple approach is a virtual constant product market maker (vAMM) similar to Perpetual Protocol v1 (with modifications), or a constant product AMM with real liquidity as in Vertex. We opt for a virtual AMM with a dynamic invariant:
We maintain virtual reserves $(X, Y)$ for base and quote assets in the pool. The mid-price offered by the AMM is $P_{\text{AMM}} = Y/X$ (if using XY=k invariant). Traders moving through the AMM will slide this price based on trade size.
However, unlike a spot AMM, these reserves are not fully backed by assets; they reflect the current aggregate position of the AMM. The actual assets held by the pool are the result of LP deposits plus/minus trader PnL.
The AMM’s invariant (k) can be adjusted over time to mimic funding payments or external price moves. For example, if external index price of stETH rises, we increase k such that the AMM price tracks the index. If funding is to be paid from longs to shorts, we slightly shift the AMM price favorably for shorts over time (reducing k if net longs, raising k if net shorts) to simulate the effect of funding accruing.
This essentially implements a virtual funding payment through price drift: in each funding interval, after processing payments, we re-center the AMM price to the current index price (so the AMM never strays too far).
Concentrated Liquidity Math: If using a Liquidity Book (discretized bins) model, mathematically:
The price range $[P_i, P_{i+1}]$ is partitioned into bins. Each bin holds some liquidity $L_i$. Only when price is in that bin does $L_i$ act as the local $xy=k$ liquidity.
Liquidity across bins is additive for depth; when a trade moves price through multiple bins, it consumes liquidity from each bin in sequence.
Pricing within a bin follows constant sum or invariant formulas given by the Liquidity Book AMM design (similar to Trader Joe’s Liquidity Book where each bin has a constant price until exhausted, then jumps to next bin). This yields piecewise constant pricing that updates as bins deplete or refill.
The slippage formula in such a system is easier to reason about: small trades get virtually 0 slippage if they stay within one bin; larger trades incur slippage when they eat through multiple bins, roughly proportional to how many bins they pass. The discrete bin model allows precise slippage control: the protocol can configure bin widths and liquidity such that slippage for a given notional size is bounded.
Liquidity Bins:
Each bin $i$ has a price $P_i$ and available liquidity $L_i$ (in quote terms, for example).
If a trade requires consuming $n$ bins, and bin $j$ has a price $P_j$, then the price remains $P_j$ until $L_j$ is exhausted. As soon as a bin depletes, price jumps to the next bin’s price. This creates a step-wise slippage function.
A formula for slippage in bins: If the trade size $Q$ spans bins $i$ to $i+n$, and partially into bin $i+n$, the average execution price $P_{avg}$ will be between $P_i$ and $P_{i+n}$. The worst-case slippage is to $P_{i+n}$ if $Q$ exactly equals sum of liquidity through those bins.
The protocol can target a slippage curve such that, e.g., a trade of size equal to 1% of market OI moves price by at most 0.2%. This can be achieved by tuning bin liquidities.
Inventory Cap for AMM: The AMM will have a parameter for maximum net exposure (in base units) it’s allowed to take. For instance, the pool might only allow itself to be, say, 1000 stETH long or short at most. If a trade would push it beyond, the AMM either refuses to fill beyond that (unlikely, as that would break guaranteed fill) or it dynamically increases slippage (widening the price) such that it becomes extremely expensive to go beyond that – effectively the AMM uses a very steep curve past a certain point.
Mathematically, we can implement this by altering the invariant when net exposure passes threshold $Q_{max}$. For example, switch to a more exponential price curve beyond that or just have an off-chain alert for devs to inject more capital or pause. But ideally, external arbitrageurs handle it: if AMM is near its cap, perp price will be far from index, inviting arbitrage to bring it back.
Last updated
Was this helpful?

