Liquidity Providers (LPs)
Users can become a Liquidity Provider (LP) by depositing into any perpetual market offered by the DAMM.
By doing so, LPs increase the liquidity depth and collateralisation within the market and earn:
- a pro-rata proportion of the fees generated by the exchange; and
- funding rates as a percentage of the total liquidity provided to exchange users.
LPs on Drift acquire opposing positions from new trades against the DAMM, regardless of the DAMM's net position. As such, LPs are effectively investing in an active liquidity provision strategy on Drift's DAMM.
Users are also able to LP with leverage.
When an LP adds liquidity to the DAMM, they increase the amount of liquidity on the AMM curve by increasing k.
Specifically, sqrt_k is incremented by the number of lp_shares the LP takes on (code) and so the proportion of liquidity provided to the DAMM is the ratio: lp_shares / sqrt_k.
This ratio is used throughout the code to calculate the amount of base/quote asset amounts to give to LPs.
Similarly, when an LP burns their lp_shares, k is decremented by the number of shares burned leading to a smaller k and more slippage for traders.
Initially, 90% of the fees collected by the DAMM will be given out to LPs. The disbursements are calculated as a percentage of the pro-rata liquidity provided to the DAMM.
For example, if the fee collected by the DAMM is 10 bps after filler rewards, then LPs would receive 9 bps out of the 10bps taker fee.
This fee will be reflected in an improved cost basis of the positions acquired (code).
For example, if the LP received a 1 SOL short position with a cost basis of 100 USD and earned a 1 USD fee, then the LP's final position would be a 1 SOL short with a cost basis of 101 USD (ie, the original position with a +1 USD P&L incorporated).
Note that this fraction is a higher proportion than the active JIT maker rebate.
The amount of margin available for LPs is calculated as a combination of their current unsettled position and open orders (code). The LP's unsettled position is treated as a regular market position without unrealized funding payments (see Funding section below) while the LP's open orders are treated as normal open orders (i.e., taking the largest base asset amount that can be acquired through either the open asks or bids (code)).
The number of open bids/asks for an LP share is the amount of base asset amount it takes on if the base asset reserves reached either the lower or upper bound from its current value (code). For example, if the current base asset reserves are 50 and the lower and upper bounds are 0 and 100 respectively, then the LP will have an equal amount of open bids and asks (ie, 50 open asks and 50 open bids when providing 100% of the liquidity). However, if the base asset reserves are 25 with the same bounds, then the LP will have more open asks than bids (ie, 75 open asks and 25 open bids when providing 100% of the liquidity) and so it will have a larger margin requirement than the first example (ie, 75 > 50). For full examples, check out the margin tests here.
A user that decides to provide liquidity can opt to use leverage, similar to open orders. This puts them at increased risk of liquidation. Fortunately, a liquidation will remove their LP shares (to acquire more free margin) prior to liquidating any positions and applying larger penalties. This gives LP shares more leeway prior to liquidation.
Users with LP shares who acquire positions through the DAMM acquire unsettled positions. Only once the positions are settled can they participate in funding payments. By default, the DAMM will act as the custodian of their position for funding payments prior to being settled. This means that LPs will need to be settled each funding period to earn their full funding payments.
The reason LPs only earn funding on settled positions is to defend against malicious LPs and ensure all LPs earn the correct amount of funding.
At a high level, we track how much base/quote_asset_amount to give each lp by tracking a "last_..._per_lp" variable for both the base and quote amount when they first add liquidity (ie, last_base_asset_amount_per_lp and last_quote_asset_amount_per_lp respectively). For each trade that occurs on the protocol, we update these variables so the LPs get a slice of the opposite side of the trade (ie, if a trader opens a long then the base_asset_amount_per_lp variable would be decremented to track that the lp opens a short) (code). To determine how much base/quote to give LPs when they burns their shares, we take the difference between the current per_lp values and the last per_lp values and multiply it by the number of shares they have (code).
Following a similar pattern with the funding payments (eg, using a last_funding_payments_per_lp variable which is updated each time funding payments are distributed) would not work because the per_lp metrics can only tell you how much base asset amount the LPs have in total and not how much each LP has taken on individually. Following this pattern would enable an attack where a malicious LP adds a large amount of liquidity before the funding rate is updated and removes it right after the funding is updated, earning all of the funding payment without holding any base asset amount. The solution to this problem is to give unsettled positions to LPs which don't earn funding until they call the settle_lp function and then calculate funding payments on these settled market positions like normal.
The DAMM has many protections which are implicitly applied to LPs (see ).
Guards against botting activity aimed at taking advantage of auction order flow are also in place. These guards can be fine-tuned over time.
A brief cooldown period to burn LP shares (30 seconds since the last liquidity addition) is in place to prevent the potential atomic MEV capture of flow from the protocol/non-bot LPs.