Product Recipe

How to provide Perpetual Futures Trade

Under developing Page

The following describes how the flow actually takes place when the user enters each value such as aperp=ETH amounta_{perp}=ETH \ amount and asquart=Squart amounta_{squart} = Squart \ amount.

How to make Squart(√ETH)

First, the Uniswap v3 LP position shall be minted with the following Tokens:

requiredeth=asquart2(1p1pb)required_{eth}=\frac{a_{squart}}{2}(\frac{1}{\sqrt{p}}-\frac{1}{\sqrt{p_b}})

requiredusdc=asquart2(ppa)required_{usdc}=\frac{a_{squart}}{2}(\sqrt{p}-\sqrt{p_a})

where, m=Marginm= Margin, p=ETH pricep= ETH \ price, Pa=LowerPricerangeP_a = Lower Price_{range} and Pa=HigerPricerangeP_a = Higer Price_{range}.

In addition, add the following Token to retrieve Squart(√ETH).

offseteth=asquart21pboffset_{eth}=\frac{a_{squart}}{2}\frac{1}{\sqrt{p_b}}

offsetusdc=asquart2paoffset_{usdc}=\frac{a_{squart}}{2}\sqrt{p_a}

Therefore, the total Token amount of each of the above is required. See this Paper for detailed instructions.

Trading (entry position creation)

First, Exchange ETH and USDC with Uniswap.

SwappedForSquart=p(requiredeth+offseteth)SwappedForSquart=p'*(required_{eth} + offset_{eth})

entryperp=paperpentry_{perp}=p'*a_{perp}

entrysquart=requiredusdc+offsetusdc+SwappedForSquartentry_{squart}=required_{usdc}+offset_{usdc}+SwappedForSquart

where, p=ETH Pricetradep' = ETH \ Price_{trade} and The unit on the left side of the formula is the value (unit price x quantity).

Position's Value and Vault's Value

vp=paperpentryperp+pasquartentrysquartv_p=p * a_{perp} - entry_{perp} + \sqrt{p} * a_{squart} - entry_{squart}

VaultValue=vp+mVaultValue = v_p + m

Asset and Debt Concept

Treat the following as an ASSET for positive cases and a DEBT for negative cases.

asseteth=aperp+offsetethasset_{eth} = a_{perp} + offset_{eth}

assetusdc=entryperpentrysquart+offsetusdcasset_{usdc}=-entry_{perp}-entry_{squart}+offset_{usdc}

As shown in this Paper, the OFFSET changes depending on the relocation of the range.

Reallocate Position

Protocol temporarily undertakes the liability when it relocates in place of User. This is expressed as Reallocation. The new debt needed at this time, or the debt to be returned, is as follows:

RequiredETH=TotalSquartAmount2(1paprev1pacurrent)Required_{ETH}=\frac{TotalSquartAmount}{2}(\frac{1}{\sqrt{p_{a_{prev}}}}-\frac{1}{\sqrt{p_{a_{current}}}})

RequiredUSDC=TotalSquartAmount2(pbprevpbcurrent)Required_{USDC}= \frac{TotalSquartAmount}{2}(\sqrt{p_{b_{prev}}}-\sqrt{p_{b_{current}}})

On the next trade, the debt is transferred to the trader by updating the offset.

offsetethoffseteth+asquart2(1paprev1pacurrent)offset_{eth} ← offset_{eth} + \frac{a_{squart}}{2}(\frac{1}{\sqrt{p_{a_{prev}}}}-\frac{1}{\sqrt{p_{a_{current}}}})

offsetusdcoffsetusdc+asquart2(pbprevpbcurrent)offset_{usdc} ← offset_{usdc} + \frac{a_{squart}}{2}(\sqrt{p_{b_{prev}}}-\sqrt{p_{b_{current}}})

The interest payments that occur while the protocol is shouldering the debt accumulate as ReallocationFeeGrowth.

protocolReallocationPositionUSDC += required USDC for reallocation
protocolReallocationPositionETH += required ETH for reallocation
ReallocationFeeGrowthETH += protocolReallocationPositionETH * (SupplyInterestGrowthETH - lastInterestGrowthETH)
ReallocationFeeGrowthUSDC += protocolReallocationPositionUSDC * (SupplyInterestGrowthUSDC - lastInterestGrowthUSDC)

Fee

This is expressed as a premium when considered as Option and as an interest rate when considered as Lending. The User earns Fee income from the Asset and pays a Fee on the Debt.

// 
let net_eth_interest
let net_usdc_interest

if(asset_{eth} >= 0) {
 net_eth_interest = asset_{eth}*(SupplyInterestGrowthETH - lastInterestGrowthETH)
} else {
 net_eth_interest = asset_{eth}*(BorrowInterestGrowthETH - lastInterestGrowthETH)
}

if(asset_{usdc} >= 0) {
 net_usdc_interest += asset_{usdc}*(SupplyInterestGrowthUSDC - lastInterestGrowthUSDC)
} else {
 net_usdc_interest += asset_{usdc}*(BorrowInterestGrowthUSDC - lastInterestGrowthUSDC)
}

if(a_{squart} >= 0) {
 net_usdc_interest += a_{squart}*(SupplyPremiumGrowth - lastPremiumGrowth)
 net_eth_interest += a_{squart}*TradeFeeETH
 net_usdc_interest += a_{squart}*TradeFeeUSDC
} else {
 net_usdc_interest += a_{squart}*(BorrowPremiumGrowth - lastPremiumGrowth)
}

if(a_{squart} > 0) {
  net_usdc_interest += a_{squart} * (ReallocationFeeGrowthUSDC - lastReallocationFeeGrowthUSDC)
  net_eth_interest += a_{squart} * (ReallocationFeeGrowthETH - lastReallocationFeeGrowthETH)
}

net_interest = net_usdc_interest + net_eth_interest * p

Debt Value

// 
let debtValue
if(asset_{eth} < 0) {
 debtValue += -asset_{eth} * price_{eth}
}
if(asset_{usdc} < 0) {
 debtValue += -asset_{usdc}
}

The settlement penalty is 0.05% of this debtValue.

Min Deposit

minValueWithinRange=min(v(pR),v(pR))minValueWithinRange =min(v(pR), v(\frac{p}{R}))

minDeposit=PositionValueminValueWithinRangeminDeposit = PositionValue - minValueWithinRange

Where, R = risk params and it sets as 1.2.

Liquidation Price

Find √X satisfy vx=minDepositv_x = minDeposit

x1=(asquart+asquart2aperp(entryperpentryperp+m))R2aperp\sqrt{x_1}=\frac{(-a_{squart}+\sqrt{a_{squart}^2-a_{perp}*(-entry_{perp}-entry_{perp}+m)}) * \sqrt{R}}{2a_{perp}}

x2=(asquartasquart2aperp(entryperpentryperp+m))2aperpR\sqrt{x_2}=\frac{(-a_{squart}-\sqrt{a_{squart}^2-a_{perp}*(-entry_{perp}-entry_{perp}+m)})}{2a_{perp} * \sqrt{R}}

Margin Available

VaultValue=Margin+PositionValueVault Value = Margin + Position Value

MarginUtilizing=Min.DepositMargin Utilizing = Min. Deposit

MarginAvailable=VaultValueMarginUtilizingMarginAvailable = VaultValue - Margin Utilizing

WithdrawableMargin=min(MarginAvailable,Margin)Withdraw-ableMargin=min(MarginAvailable, Margin)

Last updated