101 lines
4.1 KiB
Plaintext
101 lines
4.1 KiB
Plaintext
# Drift AMM
|
||
|
||
The Automated Market Maker (AMM) is Drift's source of guaranteed constant liquidity for the exchange.
|
||
|
||
## Introduction
|
||
|
||
Drift uses a backstop AMM as a source of guaranteed constant liquidity, providing constant liquidity to be taken against asynchronously.
|
||
|
||
Drift's v1 featured a Dynamic AMM which was an iteration on top of Perpetual Protocol's innovation - the [virtual AMM (vAMM)](https://blog.perp.fi/a-deep-dive-into-our-virtual-amm-vamm-40345c522eeb), except with configurable parameters, namely:
|
||
|
||
- **Peg:** a price multiplier
|
||
|
||
- **K:** liquidity depth
|
||
|
||
- **Fee Pool:** comprised of taker fee amounts (multiple methods for fee discounts to be implemented in the future)
|
||
|
||
- **Fee Tranches:** percentage allocations from the fee pool to be distributed amongst the following operations:
|
||
|
||
- Adjusting Peg (alternatively, "repeg")
|
||
|
||
- `k` adjustments
|
||
|
||
- (Capped) funding payments
|
||
|
||
You can read more about Drift's v1 AMM design [here](https://www.notion.so/driftprotocol/Drift-AMM-deep-dive-ff154003aedb4efa83d6e7f4440cd4ab#861bdbceda8a45a38600a0d9d762ee25).
|
||
|
||
## Drift v3 AMM
|
||
|
||
Drift’s v3 AMM is still a AMM using a constant product curve but now includes external [Backstop AMM Liquidity (BAL)](/protocol/glossary) a concentration factor, and dynamic spread/peg that programmatically update prior to filling trades.
|
||
|
||
The mechanics behind the dynamic spread and peg are:
|
||
|
||
1. Inventory adjusted spreads
|
||
|
||
2. Oracle live pricing/volatility
|
||
|
||
<Steps>
|
||
### Inventory Adjusted Spreads
|
||
|
||
In a typical constant product AMM, the AMM quotes the same price for buys/sells and charges a flat fee.
|
||
|
||
To implicitly utilise a dynamic fee, Drift v3's AMM quotes different prices for buys and sells. The offset from the mid-price is dynamic based on the current inventory.
|
||
|
||
To do so, there will be 3 points tracked on the constant product curve: the bid price and ask price, and a point between the reservation price.
|
||
|
||

|
||
|
||
Base long spread and short spread are currently set as:
|
||
|
||
`bid/ask price = reservation price ± base_spread + f(inventory, balance, ...)`
|
||
|
||
The long and short spread can be asymmetric due to changes in the underlying inventory skew and market buy/sell pressure. Ultimately, the ask - bid can never exceed the max spread (percentage calculated using the current valid oracle price).
|
||
|
||
The bid/ask points on the curve are calculated as follows (exact efficient integer math method calculated on contract):
|
||
|
||
` bid_quote_reserve = quote_reserve - (quote_reserve / (100%/short_spread))`
|
||
|
||
`ask_quote_reserve = quote_reserve + (quote_reserve / (100%/long_spread))`
|
||
|
||
The `quote_reserve` is defined as the total AMM reserves of the quote asset. Then using the same k to back out the base_reserve for the bid/ask curves as well.
|
||
|
||
### Oracle Live Pricing
|
||
|
||
The AMM's reservation price gets updated regularly through Drift's live oracle-based pricing.
|
||
|
||
This pricing mechanism updates an asset's mark price towards its oracle price, achieving:
|
||
|
||
- more accurate pricing; and
|
||
|
||
- better entries and exits closer to oracle price.
|
||
|
||
The mark price is updated each time the oracle updates its price and when the contract is interacted with.
|
||
</Steps>
|
||
|
||
### Oracle Live Pricing Sequence
|
||
|
||
Every time a trader wants to fill against the AMM, the AMM will be updated in the same slot with a valid oracle price (see [Oracles](file:///trading/oracles)).
|
||
|
||
<Steps>
|
||
### Step: Check the oracle price
|
||
|
||
The AMM checks the oracle price.
|
||
|
||
### Step: Move peg toward oracle
|
||
|
||
The AMM moves its peg toward the oracle price.
|
||
|
||
### Step: Set bid/ask spread
|
||
|
||
The AMM sets its bid/ask spread versus its reservation price.
|
||
|
||
### Step: Fill order
|
||
|
||
The order will fill according to the bid/ask price if the order has lived longer than the minimum duration for AMM fills (10 slots).
|
||
|
||
</Steps>
|
||
|
||
The overall spread will increase if the AMM is heavily levered or in debt. The oracle price and reservation price are always within this spread. Effective leverage is a function of many market stats, including Inventory P\&L and collateral within the fee pool in the terminal state.
|
||
|
||
The reservation (AMM) price is the `quote/base reserves * peg`.
|