Search…
⌃K

How to calculate estimated APR, Debt ratio, and Liquidation price

This calculation logic ignores price impact, slippage and swap fee. Only consider APR from trading fee.

UniV2-like Pools

Users input

Description
Variable
Example
Token A name
tokenA
ETH
Token B name
tokenB
USDC
Token A supply amount
supplyA
10
Token B supply amount
supplyB
10000
Leverage
leverage
3
Borrow ratio tokenA : tokenB (0-1)
borrowRatio
0.5
Farming duration (days)
duration
60
Expected token A price
newPriceA
1500
Expected token B price
newPriceB
1
No calculation needed
Description
Variable
Example
Token A price
priceA
1000
Token B price
priceB
1
Farming APR (7 days avg., 1x)
farmAPR
40%
Token A borrow interest
borrowAPRA
20%
Token B borrow interest
borrowAPRB
10%
Token A collateral factor
collA
8360
Token B collateral factor
collB
9598
LP collateral factor
collLP = min(collA, collB)
8360
Token A borrow factor
borrA
11961
Token B borrow factor
borrB
10419
Calculation needed -- at day = 0
Description
Variable
Logic
Example
priceA : priceB
priceAtoB
priceA / priceB
1000
Position Value (in tokenB)
posValue
leverage * (supplyA * priceAtoB + supplyB)
60000
liquidity
liquidity
posValue / (2 * sqrt(priceAtoB))
948.68
Total debt (in tokenB)
debtAmt
(leverage-1) * (supplyA * priceAtoB + supplyB)
40000
Token A debt amt
debtA
debtAmt * borrowRatio / priceAtoB
20
Token B debt amt
debtB
debtAmt * (1-borrowRatio)
20000
Calculation needed (at day = duration)
PnL
Description
Variable
Logic
Example
newPriceA : newPriceB
newPriceAtoB
newPriceA / newPriceB
1500
Position token A amt
newPosA
(1 + duration * farmAPR / 365) * liquidity / sqrt(newPriceAtoB)
26.11
Position token B amt
newPosB
(1 + duration * farmAPR / 365) * liquidity * sqrt(newPriceAtoB)
39158.28
Position token A amt
newDebtA
(1 + duration * borrowAPRA / 365) * debtA
20.66
Position token B amt
newDebtB
(1 + duration * borrowAPRB / 365) * debtB
20328.77
Net token A amt
netA
newPosA - newDebtA
5.45
Net token B amt
netB
newPosB - newDebtB
18829.38
Net value (in tokenB)
netValue
netA * newPriceAtoB + netB
27004.51
Hold value (in tokenB)
holdValue
supplyA * newPriceAtoB + supplyB
25000
PnL(%) vs Hold
pnl
(netValue / holdValue - 1) * 100%
8.02%
Debt Ratio
Description
Variable
Logic
Example
Position collateral credit
posCollCredit
(newPosA * newPriceAtoB + newPosB) * collLP
654748382.5
Position borrow credit
posBorrCredit
newDebtA * newPriceAtoB * borrA + newDebtB * borrB
582433933.3
debt ratio (%)
debtRatio
posBorrCredit / posCollCredit * 100%
88.96%
Liquidable Price : newPriceAtoB > 2694 or newPriceAtoB < 272.73
Calculation: posCollCredit < posBorrCredit
(newPosA * newPriceAtoB + newPosB) * collLP < newDebtA * newPriceAtoB * borrA + newDebtB * borrB
(1 + duration * farmAPR / 365) * 2 * liquidity * sqrt(newPriceAtoB) * collLP < newPriceAtoB * newDebtA * borrA + newDebtB * borrB
Solving B * sqrt(newPriceAtoB) < A * newPriceAtoB + C, where
  1. 1.
    newDebtA * borrA = A
  2. 2.
    (1 + duration * farmAPR / 365) * 2 * liquidity * collLP = B
  3. 3.
    newDebtB * borrB = C
newPriceAtoB>(B+B24AC2A)2newPriceAtoB > (\frac{B + \sqrt{B^2-4AC}}{2A})^2
or
newPriceAtoB<(BB24AC2A)2newPriceAtoB < (\frac{B - \sqrt{B^2-4AC}}{2A})^2