The AMM
Velocity's backstop quoter: a bounded curve whose peg tracks the oracle, whose spread widens with volatility and inventory, and which stops quoting a side rather than quote a price it cannot defend.
Velocity's AMM is a counterparty that is always present. It quotes a bid and an ask on every perpetual market without anyone having to be online, which is what lets an order fill when no human maker wants the other side. It is a backstop, not a promise: it has a finite balance sheet, it charges for the risk it takes, and on one side it can run out.
Where a constant-product curve falls short
The standard automated market maker holds virtual reserves of base and quote, keeps their product constant, quotes the ratio of the two as its price, and charges a flat fee on both sides. Three things break when that design is asked to quote a perpetual future.
- It accumulates a position it never chose and cannot charge for. A flat fee is the same whether a fill flattens the AMM's book or doubles its exposure.
- Its price is its own reserves, and reserves drift. A constant-product price refers to past trades only, so a quiet market leaves the AMM quoting a stale price against a live oracle and the first arbitrageur to notice takes the difference.
- Unbounded reserves quote unbounded size. The pure curve names a price for any size. On a perpetual that is an obligation to keep taking a position that is already too large.
Velocity corrects all three. The curve is bounded, so the AMM has a defined point at which it stops offering a side. The peg tracks the oracle, so the price it quotes around is anchored outside itself. And the spread is dynamic, rebuilt before every fill.
The bounded curve
The AMM's reserves are fenced on both sides, and how tightly those fences sit is a per-market admin setting. Pull them in and liquidity concentrates near the peg, so trades near mid slip least but the AMM reaches a fence sooner as its inventory skews. Push them out and inventory has more room to skew, at the cost of more slippage toward the edges.
What "the curve stops quoting" means
What the AMM offers on the side an order needs is the distance from its current reserve to that side's fence, halved so no single fill can consume the whole remaining side. As the reserve approaches the fence that distance shrinks toward zero, and at the fence the AMM offers nothing on that side.
So the AMM is always there in the sense that it needs no counterparty and no operator to quote, but it is not inexhaustible. Sustained one-way flow walks the reserve to a fence, that side goes quiet, and orders needing it wait for makers or for flow in the other direction. The other side keeps quoting throughout, and quotes wider.
The spread
Everything the AMM charges beyond its curve price is one number per side, rebuilt on every refresh. Four conditions widen it:
- Volatility: the oracle's own confidence band and the recent variation in the mark and oracle prices. An uncertain price is quoted wider.
- Drift from the oracle: when the AMM's own price has moved away from the oracle, the side facing that gap is floored at the size of the gap, so the AMM is not the cheapest place to buy something it is mispricing.
- Inventory: how much of its available room its position has already used, and how large that exposure is against its own retained capital.
- Funding and recent losses: whether it is currently the side paying funding, and whether the market has been losing money since the last funding update.
The two sides are not treated alike. The loaded side is the one whose fills would grow the AMM's net position; the other side is the one that would flatten it. The inventory and funding terms apply to the loaded side only, so trading in the direction that helps the AMM stays near the per-market floor and trading in the direction that hurts it gets progressively more expensive.
There is a ceiling on the total, and it rises with oracle divergence and volatility rather than staying fixed, so in the conditions where a fixed cap would force the AMM to quote a price it cannot defend, it quotes wider instead. And when the AMM's retained cushion is at or below zero, both sides widen by a factor of ten. An AMM with no cushion stops steering and starts refusing on price.
The reference price offset
Widening the spread moves the two quotes apart. The offset moves both of them the same way instead, so the distance between them is unchanged and only the midpoint travels.
It exists to handle a persistent premium. If the market has been trading above the oracle for hours and the AMM is sitting long, widening its ask does not help, because the ask is still centered on a price the market has left behind. Moving both quotes up puts its ask where buyers actually are.
The premium is estimated from the gap between the market's mark and oracle time-weighted prices and from the 24-hour average funding rate. The offset applies only when that premium and the AMM's inventory lean the same way, and is zero when they disagree. How far the midpoint may travel is bounded per market.
What happens on a fill
Every fill against the curve refreshes the AMM in the same slot against a valid oracle price. See Oracles for what makes a price valid.
Check the oracle
The AMM reads this slot's oracle price and its validity. Without a valid price the quote is not refreshed and the fill gates close.
Move the peg toward the oracle
The peg, the multiplier that converts the reserve ratio into a price, is moved toward the oracle. Peg and curve adjustments draw from one shared budget, the AMM's retained fees net of distributions. Funding sits outside that budget: what the AMM pays in funding is capped at one third of its retained equity per funding period, so a sustained imbalance cannot drain it in one period.
Rebuild the spread
Both sides are recomputed from the conditions above and written as the bid and ask the swap will execute against.
Fill
The order fills at the bid or ask price once it is eligible for an AMM fill. Eligibility has two halves: gates on the oracle's validity and the market's pause state, and timing, under which a low-risk order fills immediately while an ordinary order waits out its auction.
The oracle price and the AMM's own reserve price, meaning the price implied by its reserves alone before any spread is applied, always sit inside the quoted spread.
Just-in-time participation
Beyond quoting its own curve, the AMM can co-fill a resting maker order just in time, stepping in beside that maker at the maker's price when doing so improves its own inventory. It gives up its own curve spread on that size, and that gap is what it pays for the rebalance.
This only fires against resting maker orders. Filling directly against the AMM's curve still requires the order to be eligible for an AMM fill.
Two conditions have to hold: the market's just-in-time intensity dial, which runs from 0 to 100, is non-zero, and the fill would reduce the market's net imbalance rather than add to it.
Sizing is a sequence of caps. The AMM never takes more than half the matched amount, it stands aside when there is no valid oracle price, and it takes less when the fill price sits on the wrong side of the oracle. What it takes is scaled by the intensity dial and capped at its current net position, so a just-in-time fill can flatten its inventory but never flip it.
Where the AMM's money comes from
The AMM's retained equity is its own spread surplus plus an admin-configured share of the net taker-fee remainder. That equity is what the shared peg and curve budget spends, and it is the cushion the inventory term measures exposure against. See Where the money sits.
The AMM can also be paid a maker rebate on fills where it is the maker, at the base-tier rate of 0.0025% of filled notional rather than at the taker's own tier, so its earnings do not vary with who is taking.
The rebate is gated on an exchange-wide feature flag. While the flag is clear the AMM is paid no rebate; while it is set, part of the protocol and insurance-fund legs is redirected to the AMM. The taker's fee is identical either way. Read State.featureBitFlags for the live setting, and see Fees.
The term-by-term composition of the spread, the reference price offset, and the sizing of the AMM's participation in an auction are in AMM Spread and Quoting.
Referrals
What a referral link pays the referrer and the referee, where the reward accrues, and who can be referred.
Orderbook and keepers
Orders rest in onchain account slots, the book that sorts them is built offchain by anyone who wants to, and a permissionless instruction turns a match into a fill.