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.
import BigNumber from "bignumber.js"
import { ethers } from "ethers"
import {
getReaderContract,
getERC20Contract,
getLiquidityPool,
getAccountStorage,
Reader,
} from "@mcdex/mai3.js"
async function getLPExposure(
reader: Reader,
liquidityPool: string,
lp: string
) {
// since one pool may has multi-perps, lp may has a group of positions
const result: Array<BigNumber> = []
const pool = await getLiquidityPool(reader, liquidityPool)
const shareToken = await getERC20Contract(pool.shareToken, reader.provider)
// get shares of the LP
const lpBalance = new BigNumber((await shareToken.balanceOf(lp)).toString())
const totalLP = new BigNumber((await shareToken.totalSupply()).toString())
const shares = lpBalance.div(totalLP)
for (let i = 0; i < pool.perpetuals.size; i++) {
// read AMM positions, AMM is a trader with the address of liquidity pool
const account = await getAccountStorage(
reader,
liquidityPool,
i,
liquidityPool
)
const ammPosition = account.positionAmount
// lp shares the position
const lpPosition = ammPosition.times(shares)
result.push(lpPosition)
}
return result
}
Last modified 9mo ago