MCDEX
Search…
LP Hedging
Adding liquidity to MCDEX AMM is not risk-free. It is because the AMM has exposure to the risk when it holds positions. And LP shares such exposure. This article introduces a hedging strategy that reduces the exposure to the risk.

Exposure

AMM may hold long or short positions. LPs share the positions according to their portion of the pool.
For example, suppose AMM holds 50 BTC short positions and 200 ETH short positions. If some LP has 10% of the liquidity of the pool, the LP has exposure to 5 BTC short positions and 20 ETH short positions.
Besides, the LP’s exposure changes with the AMM’s positions changes.

Strategy

LP can dynamically hedge in the other market, which makes the LP almost delta-neutral.
  1. 1.
    Read the LP exposure to the perpetual contracts from the blockchain
  2. 2.
    Open opposite positions of the exposure in the other market to hedge
  3. 3.
    Change the hedging positions whenever AMM’s positions change

Query Exposure

Here is an example code that queries the LP’s exposure. You can get the full codes here.
1
import BigNumber from "bignumber.js"
2
import { ethers } from "ethers"
3
import {
4
getReaderContract,
5
getERC20Contract,
6
getLiquidityPool,
7
getAccountStorage,
8
Reader,
9
} from "@mcdex/mai3.js"
10
11
async function getLPExposure(
12
reader: Reader,
13
liquidityPool: string,
14
lp: string
15
) {
16
// since one pool may has multi-perps, lp may has a group of positions
17
const result: Array<BigNumber> = []
18
19
const pool = await getLiquidityPool(reader, liquidityPool)
20
const shareToken = await getERC20Contract(pool.shareToken, reader.provider)
21
22
// get shares of the LP
23
const lpBalance = new BigNumber((await shareToken.balanceOf(lp)).toString())
24
const totalLP = new BigNumber((await shareToken.totalSupply()).toString())
25
const shares = lpBalance.div(totalLP)
26
27
for (let i = 0; i < pool.perpetuals.size; i++) {
28
// read AMM positions, AMM is a trader with the address of liquidity pool
29
const account = await getAccountStorage(
30
reader,
31
liquidityPool,
32
i,
33
liquidityPool
34
)
35
const ammPosition = account.positionAmount
36
37
// lp shares the position
38
const lpPosition = ammPosition.times(shares)
39
result.push(lpPosition)
40
}
41
42
return result
43
}
Copied!
Last modified 1mo ago