OOOOOO IM DRIFTINGGG
An overview of Drift Protocol, AMMs and how it fares in the landscape of on-chain perpetual DEXs
Ah yes, perpetual swaps. The derivative invented back in 2016 that, for better or worse, ended up changing the crypto landscape. Perpetual swaps are the most popular and most traded product in all of crypto, able to greatly reward the skilled while bringing nothing less than financial agony to the reckless.
As of now, the most liquid perpetual swap contracts are hosted by centralized exchanges. How ironic. Kind of contradicts the entire “decentralization” part of the space doesn’t it? Add that to the potential conflict of interest where certain exchanges could and have been suspected of purposely frontrunning their own users’ bids, manipulating trading data, suspending withdrawals and initializing sudden liquidation wicks and spoof bids.
With these issues in mind, decentralized exchanges offering perps have started to pop up on-chain which enables traders to trade perpetual swaps without the authority, security risks and conflict of interests of centralized exchanges.
Now one of these on-chain perps-focused decentralized exchanges has a distinguishable feature that makes it stick out from most other decentralized exchanges.
Introducing Drift
Drift Protocol. A decentralized on-chain perpetual swap exchange built on Solana that uses Pyth Network as an oracle. Now what makes Drift so special is a unique type of AMM called a Dynamic Virtual Automated Market Maker (dAMM).
But before going into that, let’s briefly go over why Drift was built on Solana and not other chains like Ethereum or Layer 2s
One of the main factors on why the Drift team decided to build on Solana was the speed the network offered. For any type of exchange, speed is crucial. Considering Solana is one of the fastest blockchains there is right now with about a 400 millisecond block time, Drift is able to take full advantage of this.
The ecosystem of products and protocols in Solana that could complement Drift was also a determining factor. An example would be how Drift is looking to enable yield earning on unused deposits on their platform, doing this would require working and partnering with lending protocols
And finally, user experience. Let's take an Ethereum-based DEX like dYdX as an example. Say your funds are currently being stored in a network other than Ethereum. You would need to bridge your funds over to the Ethereum network where you’d have to pay the network’s gas fees which can be outrageously high. After that, 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 spending on gas could eventually add up to significant amounts.
By being built on a Layer 1 like Solana, taking advantage of Solana’s low gas fees, Drift users would avoid the costly and sometimes clunky experience of bridging, and the cost of depositing into Drift itself is negligible.
Now that we’ve covered why Solana is the network of choice for Drift, it’s time to get into what a dAMM is, but first we need to understand the concepts of Automated Market Makers (AMM) and Virtual Automated Market Makers (vAMM)
Automated Market Makers (AMM)
An Automated Market Maker (AMM) is essentially 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.
So 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 liquidity to the platform.
Now Drift is unique in the sense that unlike other decentralized on-chain exchanges that use a vAMM, Drift has come up with something 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 readjust the curve while also reducing the oracle price and terminal price divergence over time, presenting traders with the best prices on the market.
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 from their entire size 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), which all aim to make sure that liquidity, slippage and Drift’s mark price against its oracle price are within an acceptable range.
A deep-dive into dAMM
A dAMM has some distinct features that makes it unique compared 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. Say you enter a SOL position at the price of $100. A few moments later, the price skyrockets to $200 in a short period of time and you decide you want to sell and take profit. Well now if 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 so 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% and large funding rates are persistent. Drift also has a target slippage that they maintain, where if slippage gets too high and above their target, the curve is then re-pegged back to the oracle price.
Referring back to the previous example, with Drift’s re-pegging mechanism, traders who wish to enter SOL at $200 after the pump will enjoy low slippage while earlier traders with lower entry prices will also 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 while ‘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.
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 something called 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, then 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, then 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 Drift to provide consistently low slippage for traders.
dAMM vs Traditional Orderbooks
Every centralized exchange and most decentralized exchanges use an orderbook system. In this section, we’ll discuss an argument on 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 us have seen this happen, massive bid walls are placed at a price level, baiting traders into thinking that level is a strong support zone only for those same bids to be “spoofed” or withdrawn when price actually gets near, essentially trapping traders who tried to front run those bids that eventually got spoofed. This is a prime example of 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 available 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 such as the platform’s funding payments.
So, with it’s re-pegging mechanisms and adjustable K, you could even make a strong 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.
This diagram above visualizes it perfectly. Let’s say today you enter a $SOL position with $1,000,000 and you experience some slippage and the mark price was moved by a noticeable amount due to your position. Alright, that's an inconvenience. Now let’s fast forward a week from now, the number of active traders trading in Drift has tripled and the overall volume traded has increased tenfold. You enter a $SOL position with $1,000,000 and now you’ve noticed there’s significantly less slippage and the mark price wasn’t as affected as much as before. Let’s fast forward another week, active traders have tripled again and volume traded increased by another tenfold. You enter a $SOL position with $1,000,000 and the slippage is now significantly lower yet again and the mark price is affected even less. 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 what Drift’s positive feedback loop achieves. 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, the better the platform.
Limit Orders
Limit orders have recently arrived on Drift. After months of market orders only, Drift has finally launched limit orders that are able to be executed without an orderbook system, but instead utilizes and takes full advantage of Drift’s dAMM with a computationally efficient system called a Decentralised Limit Orderbook or DLOB.
Decentralised Limit Orderbook (DLOB)
A Decentralised Limit Orderbook (DLOB) is a decentralized system that allows limit orders to be placed against Drift’s dAMM by incentivizing off-chain ‘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” that are incentivized to fulfill limit orders are off-chain, DLOB isn’t a fully on-chain system, albeit it is a hybrid one. DLOB allows traders to enjoy the capabilities of limit orders while still experiencing the full 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. Another reason is that this “orderbook-esque” system can be computationally intensive, so keeping this process off-chain is more computationally efficient which could lead 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. If 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 will then fill this order against the dAMM and is incentivized to do so with a % reward from the fees paid by the user.
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 for a long position. Keeper bots will then notice that you’ve placed a limit order and will store this information in their data structures off-chain. After a few hours, the dAMM SOL mark price has come down to $95, the keeper bots notice this and will then market buy SOL at $95 for you against the dAMM, essentially 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 limit 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 for a short position. Keeper bots will then notice that you’ve placed a limit order and will store this information in their data structures off-chain. After a few hours, the dAMM SOL mark price has risen to $120, the keeper bots notice this and will then market sell SOL at $120 for you 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 limit order.
Also note that in some scenarios, when you actually get filled on an order, your average entry price may differ from your limit price by a very small, negligible amount. So say you placed a limit order for SOL at $100 and it gets filled, in some cases, your average entry price could actually end up being $100.021 or $99.985 instead of the original $100 you placed on your limit. It’s very negligible and doesn’t impact your trading. It doesn’t actually matter in the grand scheme of things but I just thought it was something worth noting.
Now, let’s say a scenario occurs where someone else has placed a limit order on SOL at the exact same price and time as you. In case this happens, the keeper bots would then prioritize filling whoever has placed the larger order size.
Closing Thoughts
I’ve had the chance to try Drift myself over the past few weeks. The UI is modern and clean, deposit and gas fees were negligible while the UX, barring a few nitpicks, was fairly smooth as well, and paired with Solana’s network speed, my transactions were initialized in an instant.
In case you start accusing me of larping, here’s a screenshot of me actually using the platform, and yes I did use the max amount of leverage possible for all my trades. Note that the leverage limit here is capped at 5x, and although I do understand the reasoning on why it’s capped to a 5x for now, I can’t help but wish they offered higher leverage. However, the team did mention that they are planning to up the leverage as the platform matures, so I’ll be looking forward to that. I’m also fond of the “Recent Trades” section where I basically got to watch other people live pump my bags one transaction at a time which was quite a nice and exciting feeling.
OOOO quick update, the Drift team actually rolled out a new UI which, in my opinion, looks cleaner and more “spacious” if that makes sense. Here’s a brief look at the new UI where you can go try it out yourself here.
To end it on a high note, Drift Protocol offers a smooth and fantastic UI, a fairly responsive UX, lightning fast transaction speeds and a new system in dAMM and DLOB that promises lower slippage, good liquidity without the need of traditional liquidity providers and no more market maker spoof bidding fiascos. Despite still being in its early stages with multiple features and milestones still to come, I believe Drift has the potential to become one of the most successful decentralized on-chain perpetual swap exchanges in the space and is definitely worth keeping an eye on.