Skip to Content
DevelopersConceptsOptimizations

Optimizations

Velocity’s AMM acts as a designated market maker, guaranteeing a liquidity source for traders even when no external maker is quoting. This page covers the mechanisms it uses to manage that liquidity: how it sizes its depth, when it competes for fills, and how it settles the P&L it takes on. Read it if you’re building a market maker, filler, or risk model that needs to account for AMM behavior rather than only DLOB makers.

Size your liquidity assumptions around the concentration factor

The AMM’s liquidity depth comes from k, the constant-product invariant. Increasing k while tightening the max/min base reserves lets the AMM provide the same bid/ask liquidity concentrated into a narrower price range. If you’re modeling how much size the AMM can absorb at a given price, use the market’s current k and reserve bounds rather than assuming a fixed depth: both move over time (see the next section).

Account for formulaic K adjustments in your liquidity model

After every funding-rate update, the AMM adjusts k based on the funding it just received or paid:

ConditionEffect on kDirection
Net revenue over the last hour increasedk increasesMore liquidity depth
AMM paid funding over the last hourA portion of the payment reduces kLess liquidity depth
Per-step capEach adjustment is capped at sqrt_k / 1000Max 0.1% change in sqrt_k per step

These per-step caps mean k converges toward an optimal value over time rather than jumping to it. If your integration reads k/reserves and caches them, refresh on a cadence that accounts for this drift rather than treating them as static.

An admin can disable this behavior per market with the MarketConfigFlag::DisableFormulaicKUpdate bit. Check the market’s config flags rather than assuming formulaic K updates are always active.

Expect the AMM to compete in the JIT auction

Just as market makers provide active liquidity through the JIT auction process, the AMM can also participate in it to reduce its own inventory. If you’re a maker bidding in the JIT auction, factor in that the AMM may be quoting alongside you rather than only backstopping unfilled size.

Understand how unrealized P&L gets settled

A user’s unrealized P&L against the AMM is, in principle, unbounded (for example, if BTC’s price goes toward infinity), because of:

  • Potential market imbalances
  • Live-oracle-based pricing
  • The maximum allowable spread the AMM enforces

In practice, a winning position can only be settled and withdrawn as collateral once an offsetting loss (or sufficient collected fees) has replenished the P&L settlement pool. Until then, winners may be offered discounted margin on their unrealized gains, and can withdraw their share of the pool as it grows. See P&L for the full settlement mechanism.

If a market’s unrealized P&L imbalance exceeds its per-market threshold, the margining system can discount those unrealized gains at the initial-margin stage only, not maintenance. That discount affects new positions being opened; it does not move an existing position’s liquidation threshold. These rules are covered in more detail under the Margin subheading in Cross-Collateral Deposits.

Terminal state has no cost when inventory is flat

When the AMM’s inventory is 0, repeg and k-change operations carry no terminal state cost. The AMM still tracks the market’s remaining position imbalance and uses it to size its spread and liquidity depth, within its constraints as a designated market maker.

Last updated on