This section will help you better understand the math behind the protocol. By exploring the calculations and concepts involved, you'll gain valuable insights into how the system operates and how to make informed trading/liquidity providing decisions.
Calculating Position Value
Formula:
positionValuelong=collateral+(entryPriceclosePrice−1)∗positionSize−hoursPassed∗borrowRate∗positionSizepositionValueshort=collateral+(1−entryPriceclosePrice)∗positionSize−hoursPassed∗borrowRate∗positionSize
Example:
collateral=10leverage=5positionSize=10∗5=50entryPrice=100closePrice=110hoursPassed=20borrowRate=0.00005
positionValuelong=10+(100110−1)∗50−20∗0.00005∗50positionValuelong=10+(1.1−1)∗50−20∗0.0025positionValuelong=10+0.1∗50−0.05positionValuelong=10+5−0.05positionValuelong=14.95
positionValueshort=10+(1−100110)∗50−20∗0.00005∗50positionValueshort=10+(1−1.1)∗50−20∗0.0025positionValueshort=10+(−0.1)∗50−0.05positionValueshort=10−0.5∗50−0.05positionValueshort=4.95
Calculating Entry/Close Price
Formula:
entryPricelong=marketPrice∗(1+openFee)entryPriceshort=marketPrice∗(1−openFee)closePricelong=marketPrice∗(1−closeFee)closePriceshort=marketPrice∗(1+closeFee)
Example:
marketPrice=100openFee=0.005
entryPricelong=100∗(1+0.005)entryPricelong=100∗1.005entryPricelong=100.5closePricelong=100∗(1−0.005)closePricelong=100∗(0.995)closePricelong=99.5
Calculating Position Size
Formula:
positionSize=collateral∗leverage
Example:
collateral=10leverage=5
positionSize=10∗5positionSize=50
Calculating Liquidation Price
Formula:
liquidationPricelong=entryPrice−leverageentryPrice∗collateralvalueliquidationPriceshort=entryPrice+leverageentryPrice∗collateralvalue
Example:
entryPrice=100leverage=5value=5collateral=10
liquidationPricelong=100−5100∗105liquidationPricelong=100−20∗0.5liquidationPricelong=90liquidationPriceshort=100+5100∗105liquidationPriceshort=100+20∗0.5liquidationPriceshort=110
Calculating Profit and Loss
Formula:
pnl=value−collateral
Example:
value=15collateral=10
pnl=15−10pnl=5
value=5collateral=10
pnl=5−10pnl=−5
Calculating Available Liquidity
Formula:
availableLiquidityshort=2openInteresttotal−openInterestshortavailableLiquiditylong=2openInteresttotal−openInterestlong
Example:
openInteresttotal=1000openInterestlong=300
availableLiquiditylong=21000−300availableLiquiditylong=500−300availableLiquiditylong=200
Calculating Hourly Borrow Cost
Formula:
hourlyBorrowCost=borrowRate∗positionSize
Example:
collateral=10leverage=5positionSize=10∗5=50borrowRate=0.00005
hourlyBorrowCost=0.00005∗50=0.0025
Calculating LP Token Price
Formula:
LPTokenPrice=LPTokenAmountliquidity
Example:
liquidity=1000LPTokenAmount=100
LPTokenPrice=1001000LPTokenPrice=10