Drift Protocol v2

โŒ˜K
๐Ÿ‘พWelcome to Drift Protocol
๐ŸงฎDrift DEX
๐Ÿ‘‹Getting Started
๐Ÿ“ˆPerpetual Futures
๐Ÿ“ŠSpot Margin Trading
๐ŸฆBorrow & Lend
๐Ÿ›๏ธStaking
๐Ÿ”ฌTechnical Explanations
๐Ÿ“Accounting and Settlement
โž—Borrow Interest Rate
๐Ÿ“œDelisting Process
โ›ฒDrift AMM
๐ŸƒJust-In-Time (JIT) Auctions
๐Ÿ“šKeepers & Decentralised Orderbook
โ˜ ๏ธLiquidators
๐Ÿ’งLiquidity Providers (LPs)
๐Ÿ“‹Protocol Guard Rails
๐Ÿ“Risks
๐Ÿ–ฅ๏ธDeveloper Resources
๐Ÿ“”Overview
โŒจ๏ธSDK Documentation
โŒจ๏ธTutorial: Bots
โš ๏ธTroubleshooting
๐Ÿ› ๏ธKeeper Bots
๐Ÿ› ๏ธTrading Bots
โŒจ๏ธHistorical Data (v1)
โŒจ๏ธAPI
๐Ÿ›ก๏ธSecurity
๐Ÿ›ก๏ธAudits
๐Ÿ›ก๏ธBug Bounty
โš–๏ธLegal and Regulations
๐Ÿ“Terms of Use
๐Ÿ“Disclaimer
๐Ÿ“Privacy Policy
๐Ÿ“Competition Terms and Conditions
๐Ÿ“šGlossary
Docs powered byย archbeeย 
16min

Drift AMM

Introduction

Drift uses a backstop AMM as a source of guaranteed constant liquidity for the exchange, providing constant liquidity to be taken against asynchronously.

Drift's v1 featured a Dynamic AMM (DAMM) which was an iteration on top of Perpetual Protocol's innovation - the virtual AMM (vAMM), 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

To read more about Drift's v1 DAMM, read here.

Drift v2 AMM

Driftโ€™s v2 AMM is still a vAMM using a constant product curve, but now includes external Liquidity Providers (LPs), a concentration factor, and dynamic spread/peg that programatically update prior to filling trades.

The mechanics behind the dynamic spread and peg are:

  1. Inventory adjusted spreads
  2. Oracle live pricing

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 v2's AMM quotes different prices for buys and sells. The offset from the mid price is dynamic based upon 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 for the reservation price.

Document image

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 current valid oracle price).

The bid/ask points on the curve are calculated as follows:

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.

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).

The sequence is:

  1. The AMM checks the oracle price
  2. The AMM move its peg๏ปฟ toward the oracle price
  3. The AMM sets its bid/ask spread
  4. The order will fill according to the bid/ask spread if the JIT auction has expired

The overall spread will increase if the AMM has a large effective leverage. 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 fee pool in the terminal state.

The reservation (AMM) price is the quote/base reserves * peg.

Updated 05 Dec 2022
Did this page help you?
Yes
No
UP NEXT
Optimisations
Docs powered byย archbeeย 
TABLE OF CONTENTS
Introduction
Drift v2 AMM
Inventory Adjusted Spreads
Oracle Live Pricing