Drift Protocol: An Overview
August 4th, 2022

Perpetual swaps are the most popular and most traded product in all of crypto.

Currently, the most liquid perpetual swap contracts are hosted by centralized exchanges. Ironic given the supposed decentralization aspect of the space. Add to that the conflict of interest where centralized exchanges could be and have been suspected of frontrunning their own users’ bids, manipulating trading data, suspending withdrawals, initializing liquidation wicks and spoofing bids.

With this in mind, decentralized perpetual futures exchanges have started to pop up on-chain, enabling traders to trade perpetual swaps without the authority, security risks and conflict of interests of centralized exchanges.

Introducing Drift

Drift Protocol is a decentralized on-chain perpetual swap exchange built on Solana, using Pyth Network as an oracle

One of the main reasons why the team at Drift Labs decided to build on Solana was speed. For any exchange, speed is essential. Solana is one of the fastest blockchains there currently is with a block time of 400 milliseconds that Drift intends to take full advantage of.

The ecosystem of products and protocols in Solana that could complement Drift was also a factor. Drift is currently looking to enable yield-earning on their platform’s unused deposits and doing this would require working and partnering with lending and yield aggregating protocols

The last reason to highlight, user experience. For an Ethereum-based DEX like dYdX, you would need to bridge your funds over to the Ethereum network where you’d have to pay Ethereum’s gas fees (which can be outrageously high). Then you’d need to pay even more gas to deposit your funds into dYdX itself. This poses a big problem for smaller-sized traders, and while it may not seem like a huge problem for larger-sized traders, the constant need to spend gas anytime you want to deposit from another chain can add up to significant amounts.

By taking advantage of Solana and it’s low fees, Drift users would avoid the costly and oftentimes sub-par experience of bridging while keeping the cost of depositing into Drift itself negligible.

Now that we’ve covered why Solana is the network of choice for Drift, it’s time to get into the concepts of Automated Market Makers (AMM) and Virtual Automated Market Makers (vAMM)

Automated Market Makers (AMM)

An Automated Market Maker (AMM) is a system that automates the process of providing liquidity. It incentivizes users to become liquidity providers in exchange for a share of transaction fees and free tokens.

A Virtual AMM (vAMM) is essentially an AMM for derivative contracts like perpetual swaps.

The nature of a vAMM is that the more people use it, the better it works since there would then be more people to provide additional liquidity to the platform.

Drift is unique in the sense that they’ve come up with what’s called a Dynamic Virtual AMM or dAMM.

Dynamic Virtual Automated Market Maker (dAMM)

A Dynamic Virtual Automated Market Maker (dAMM) aims to reduce slippage for traders over time while being adaptable to the demand for trading in the market, essentially fixing slippage issues present from a vAMM by using a portion of the fees collected by the platform to re-adjust the curve while also reducing the oracle price and terminal price divergence over time, presenting traders with the best possible prices on the market.

source: Drift Labs
source: Drift Labs

This diagram is an excellent visualization of how the platform’s fees are used to provide traders with the best prices on the market. When entering a position, traders pay a 0.1% fee which goes into Drift Protocol’s fee pool.

(A trader with $1000 going all in with 1x leverage will pay a $1 fee but the same trader going all in with 5x leverage will pay a $5 fee since the total position size would then be $5000 due to the 5x leverage)

A portion of the fees collected in this fee pool is used to fulfill the 3 operations seen above (Repeg, K adjustment and Funding Payments), all with the purpose of making sure that liquidity, slippage and Drift’s mark price against its oracle price are within acceptable ranges.

A deep-dive into dAMM

A dAMM has distinct features that makes it unique to a vAMM.

These features are its re-peg mechanism and an adjustable K

Re-Peg Mechanism

Drift’s re-pegging mechanism solves price problems where the mark price and the oracle price starts to drift too far away from one another.

How a traditional repegging mechanism works

Let’s use a simple example where you enter a SOL position at a price of $100. In a short period of time, the price skyrockets to $200 and you decide you want to sell and take profit. When you try to exit at the price of $200, you’ll experience high slippage because you’ll be trading at the far end of the curve where there’s minimal liquidity.

To combat this, a vAMM with a traditional re-pegging mechanism would need to have sufficient demand from arbitrageurs in order to move price, if not, then the vAMM would need to reduce k and re-peg or “move” the curve so that liquidity is concentrated to the price point you’re trading at, closer to that $200 price point. But doing thiss would lead to higher slippage for earlier traders at price points where liquidity was diluted from.

How Drif’s re-pegging mechanism works

Drift’s re-pegging mechanism handles this by initiating a re-peg event anytime certain conditions are met. These conditions are when:

  • Mark price to oracle price divergence is greater than 10%
  • Large funding rates are persistent

Drift has a target slippage that they maintain, where if slippage gets too high and above their target, the curve is re-pegged back to the oracle price.

Referring back to the previous example, with Drift’s re-pegging mechanism, traders wanting to enter SOL at $200 after the pump will enjoy low slippage while earlier traders with lower entry prices will be able to exit with low slippage with better close prices.

Adjustable K

K refers to the constant variable in the constant product curve of  [ x * y = K ]  used by Drift’s dAMM.

‘x’ refers to one asset

‘y’ refers to another asset

‘K’ refers to the virtual pool or liquidity depth of those 2 assets

Note that ‘K’ is the curve and is constant while ‘x’ and ‘y’ are the variables

vAMM with the formula [ x * y = K ]
vAMM with the formula [ x * y = K ]

The picture above represents a vAMM with the formula [ x * y = K ]. In this example, ‘x’ or the x-axis is SOL, ‘y’ or the y-axis is USDC and ‘K’ is the curve that represents the liquidity depth of the SOL/USDC pair.

In this diagram above, you can see how if you were to take a long position on SOL, you’d end up at point A’ on the curve, since you’d be taking SOL out of Drift’s SOL pool and depositing your USDC into Drift’s USDC pool.

Vice versa, if you were to close that long position or take a short position on SOL, you’d end up lower on the curve at point A since you’d be taking USDC out of Drift’s pool and depositing SOL into Drift’s pool

How an Adjustable K works

K is adjusted when certain conditions are met, in which those conditions could lead to a k-error bias. A k-error bias occurs when either k was set too high or too low and is measured by the divergence between the mark price and the oracle price.

K would be deemed as being set too low if the number of longs is greater than the number of shorts and oracle price is less than mark price. K that is too low would result in discouragingly high slippage for traders.

K would be deemed as being set too high if the number of longs is greater than the number of shorts and the oracle price is greater than mark price. But if K is too high, arbitrageurs will find it difficult to maintain price levels.

To protect users from these problems, the conditions for a k-error bias is checked after every funding update. If there comes a scenario where these conditions are found to be of statistical significance, K will be incrementally adjusted.

If re-pegging helps in situations where market price starts straying away from oracle price, then an Adjustable K helps in situations where growing open interest (OI) starts causing higher trade sizes to lead to higher slippage in the vAMM.

So as OI and the number of participants grows, whenever the long/short balance delta hits 0 or is balanced, Drift’s dAMM adjusts the ‘K’ formulaically to a rolling count of OI and trading size, enabling consistently low slippage for traders.

dAMM vs Traditional Orderbooks

Every centralized exchange and some decentralized exchanges use an orderbook system. In this section, we’ll make a case for how and why a dAMM could be a better system than an orderbook.

Orderbooks are reliant on external market makers. A platform with an orderbook system is prone to spoof bids. A lot of traders have seen this happen. Large bid walls are placed at a price level, traders are baited into thinking that level is a strong support zone only for those same bids to be “spoofed” or withdrawn when price gets near, essentially trapping traders who tried to front run those eventually spoofed bids. This is one of the main drawdowns of an orderbook system; that liquidity can be pulled out anytime from the orderbooks.

This is where a dAMM shines. A dAMM operates on full mathematical transparency. You can’t spoof bids in a trading platform that uses a dAMM. In the sense that orderbooks rely on external market makers to extract spreads from the market and external liquidity providers to provide liquidity to the market, a dAMM does not require external liquidity other than the people actually trading on the platform.

In terms of liquidity, Drift doesn’t need a traditional 50/50 liquidity pool to have liquidity for their trading pairs. Instead of liquidity providers, what they need are arbitrageurs. Arbitrageurs are important because Drift needs arbitrageurs to keep and make sure that the mark prices in it’s dAMM are in line with the underlying index prices. To do this, arbitrageurs would need to take the other side of trades and hedge themselves. They would be incentivized to do so with rewards i.e. the platform’s funding payments.

With re-pegging mechanisms and adjustable K, you could make an argument that trading with a dAMM is more “pure” in terms of price action compared to an orderbook system.

Positive Feedback Loop

Drift also has a positive feedback loop in regards to the amount of fees it collects and the volume traded on the platform itself which incentivizes volume growth, which in turn leads to better liquidity, less slippage and better mark prices.

source: Drift Labs
source: Drift Labs

Today you enter a $1,000,000 SOL position, experience some slippage and the mark price was moved by a noticeable amount due to your position. Alright, that's an inconvenience.

Fast forward a week from now, the number of traders actively trading in Drift have tripled and the overall volume being traded has increased tenfold. You enter a $1,000,000 SOL position and now you’ve noticed significantly less slippage and the mark price wasn’t as affected as much as before.

Fast forward another week, the number of active traders have tripled again and volume being traded increased by another tenfold. You enter a $1,000,000 SOL position with and the slippage is now significantly lower and there’s even less of an effect to the mark price.

Fast forward another week where volume has increased tenfold, slippage becomes even lower. Fast forward yet another week where volume has increased, slippage is even lower yet again and so on and so forth…

This is Drift’s positive feedback loop . The more volume is traded on the platform, the more fees collected that go into Drift’s fee pool. The more fees Drift has in it’s pool, the more fees can be used for its re-pegging mechanism and its adjustable K. The more re-peg events occur and the more times K is adjusted, the more volume is traded on the platform, and so on and so forth.

Essentially, the more volume traded on the platform, the better slippage and mark prices

Limit Orders

Drift’s limit orders are able to be executed without an orderbook system, instead utilizing and taking full advantage of Drift’s dAMM with a computationally efficient system called a Decentralised Limit Orderbook (DLOB)

Decentralised Limit Orderbook (DLOB)

A Decentralised Limit Orderbook (DLOB) is a system that allows limit orders to be placed against Drift’s dAMM by incentivizing “keepers” to fulfill those orders.

“Keepers” are off-chain bots that anyone can build and run whose sole purpose is to track, store, sort and fill the limit orders of Drift traders.

Since these “keeper bots” are off-chain, DLOB isn’t a fully on-chain system, albeit it’s more of a hybrid one. DLOB allows traders to enjoy the capabilities of limit orders while still experiencing the benefits of Drift’s dAMM.

The reason why the limit orders stored and sorted by keeper bots are off-chain is that it enables Drift itself to still maintain full decentralization as the data stored by keepers are just copies of the original data.

Another reason is that this “orderbook-esque” system can be computationally intensive and keeping this process off-chain is more computationally efficient, leading to better performance during periods of high network congestion.

How a DLOB works

Keepers or keeper bots continuously track and monitor Drift users’ on-chain accounts and activity for any limit orders. When a user places a limit order, these keepers then track and store this limit order off-chain in their own data structure and sorts them alongside other limit orders placed by other users, first sorted chronologically, then by size. In the case that Drift’s dAMM mark price hits the user’s limit price, the keeper is incentivized to fill this order against the dAMM with a % reward from the fees paid by the user.

source: Drift Labs
source: Drift Labs

Let’s use real examples to help grasp this concept better. Say the current dAMM mark price of SOL is $100. You want to long SOL at a price of $95, so you place a limit order at $95. Keeper bots will notice that you’ve placed a limit order and will store this information in their data structures off-chain. A few hours pass and the dAMM’s SOL mark price has come down to $95, the keeper bots notices and will market buy SOL for you at $95 against the dAMM, filling your $95 limit order placed a few hours ago. You then pay Drift’s 0.1% trading fee, and the keeper bots are rewarded with a percentage of this fee for fulfilling your order.

Same mechanics applies for the short side too. Say the current dAMM mark price of SOL is $100. You want to short SOL at a price of $120, so you place a limit order at $120. Keeper bots will notice that you’ve placed a limit order and will store this information in their data structures off-chain. A few hours pass and the dAMM's SOL rises to $120, the keeper bots notices and will market sell SOL for you at $120 against the dAMM, essentially filling your $120 limit order placed a few hours ago. You then pay Drift’s 0.1% trading fee, and the keeper bots are rewarded with a percentage of this fee for fulfilling your order.

Also note that in some scenarios, when you actually get filled on an order, your average entry price may slightly differ from the price you set a limit for, just by a small amount.

If you placed a limit order for SOL at $100 and it gets filled, sometimes your average entry price could end up being $100.021 or $99.985 instead of the original $100 you placed. It’s very negligible and doesn’t actually matter in the grand scheme of things but just thought it was worth noting.

In a scenario where someone else has placed a limit order on SOL at the exact same price and time as you, the keeper bots would then prioritize filling whoever has placed the larger order size.

Closing Thoughts

I’ve had the chance to try Drift over the past few weeks. The UI is clean, deposit and gas fees were negligible while the UX, barring some nitpicks, was fairly smooth and paired with Solana’s speed, my transactions were initialized quickly

Drift Protocol offers a smooth UI, a fairly responsive UX, fast transaction speeds and a new system in dAMM and DLOB that promises lower slippage and good liquidity without the need of traditional liquidity providers and no more market maker spoof bidding fiascos.

You can trade on Drift here:

Despite still being in its early stages with multiple features and milestones still to come, Drift has the potential to become one of the most successful decentralized on-chain perpetual swap exchanges in the space and is worth keeping an eye on.

Thanks for reading. And a thank you to BigZ and Cindy Leow for helping with proofreading! If you want to get notified about future posts or give any input/feedback, subscribe and follow me on Twitter. Or don’t. It’s up to you.

This article was first published on 9 March 2022 in Substack. Minor edits were made for formatting.

Subscribe to knarb
Receive new entries directly to your inbox.
View collectors
This entry has been permanently stored on-chain and signed by its creator.