Under developing Page
The following describes how the flow actually takes place when the user enters each value such as a p e r p = E T H a m o u n t a_{perp}=ETH \ amount a p er p = ET H am o u n t and a s q u a r t = S q u a r t a m o u n t a_{squart} = Squart \ amount a s q u a r t = Sq u a r t am o u n t .
How to make Squart(√ETH)
First, the Uniswap v3 LP position shall be minted with the following Tokens:
r e q u i r e d e t h = a s q u a r t 2 ( 1 p − 1 p b ) required_{eth}=\frac{a_{squart}}{2}(\frac{1}{\sqrt{p}}-\frac{1}{\sqrt{p_b}}) re q u i re d e t h = 2 a s q u a r t ( p 1 − p b 1 )
r e q u i r e d u s d c = a s q u a r t 2 ( p − p a ) required_{usdc}=\frac{a_{squart}}{2}(\sqrt{p}-\sqrt{p_a}) re q u i re d u s d c = 2 a s q u a r t ( p − p a )
where, m = M a r g i n m= Margin m = M a r g in , p = E T H p r i c e p= ETH \ price p = ET H p r i ce , P a = L o w e r P r i c e r a n g e P_a = Lower Price_{range} P a = L o w er P r i c e r an g e and P a = H i g e r P r i c e r a n g e P_a = Higer Price_{range} P a = H i g er P r i c e r an g e .
In addition, add the following Token to retrieve Squart(√ETH).
o f f s e t e t h = a s q u a r t 2 1 p b offset_{eth}=\frac{a_{squart}}{2}\frac{1}{\sqrt{p_b}} o ff se t e t h = 2 a s q u a r t p b 1
o f f s e t u s d c = a s q u a r t 2 p a offset_{usdc}=\frac{a_{squart}}{2}\sqrt{p_a} o ff se t u s d c = 2 a s q u a r t 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.
S w a p p e d F o r S q u a r t = p ′ ∗ ( r e q u i r e d e t h + o f f s e t e t h ) SwappedForSquart=p'*(required_{eth} + offset_{eth}) Sw a pp e d F or Sq u a r t = p ′ ∗ ( re q u i re d e t h + o ff se t e t h )
e n t r y p e r p = p ′ ∗ a p e r p entry_{perp}=p'*a_{perp} e n t r y p er p = p ′ ∗ a p er p
e n t r y s q u a r t = r e q u i r e d u s d c + o f f s e t u s d c + S w a p p e d F o r S q u a r t entry_{squart}=required_{usdc}+offset_{usdc}+SwappedForSquart e n t r y s q u a r t = re q u i re d u s d c + o ff se t u s d c + Sw a pp e d F or Sq u a r t
where, p ′ = E T H P r i c e t r a d e p' = ETH \ Price_{trade} p ′ = ET H P r i c e t r a d e and The unit on the left side of the formula is the value (unit price x quantity).
Position's Value and Vault's Value
v p = p ∗ a p e r p − e n t r y p e r p + p ∗ a s q u a r t − e n t r y s q u a r t v_p=p * a_{perp} - entry_{perp} + \sqrt{p} * a_{squart} - entry_{squart} v p = p ∗ a p er p − e n t r y p er p + p ∗ a s q u a r t − e n t r y s q u a r t
V a u l t V a l u e = v p + m VaultValue = v_p + m Va u lt Va l u e = v p + m
Asset and Debt Concept
Treat the following as an ASSET for positive cases and a DEBT for negative cases.
a s s e t e t h = a p e r p + o f f s e t e t h asset_{eth} = a_{perp} + offset_{eth} a sse t e t h = a p er p + o ff se t e t h
a s s e t u s d c = − e n t r y p e r p − e n t r y s q u a r t + o f f s e t u s d c asset_{usdc}=-entry_{perp}-entry_{squart}+offset_{usdc} a sse t u s d c = − e n t r y p er p − e n t r y s q u a r t + o ff se t u s d c
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:
R e q u i r e d E T H = T o t a l S q u a r t A m o u n t 2 ( 1 p a p r e v − 1 p a c u r r e n t ) Required_{ETH}=\frac{TotalSquartAmount}{2}(\frac{1}{\sqrt{p_{a_{prev}}}}-\frac{1}{\sqrt{p_{a_{current}}}}) R e q u i re d ET H = 2 T o t a lSq u a r t A m o u n t ( p a p re v 1 − p a c u rre n t 1 )
R e q u i r e d U S D C = T o t a l S q u a r t A m o u n t 2 ( p b p r e v − p b c u r r e n t ) Required_{USDC}= \frac{TotalSquartAmount}{2}(\sqrt{p_{b_{prev}}}-\sqrt{p_{b_{current}}}) R e q u i re d U S D C = 2 T o t a lSq u a r t A m o u n t ( p b p re v − p b c u rre n t )
On the next trade, the debt is transferred to the trader by updating the offset.
o f f s e t e t h ← o f f s e t e t h + a s q u a r t 2 ( 1 p a p r e v − 1 p a c u r r e n t ) offset_{eth} ← offset_{eth} + \frac{a_{squart}}{2}(\frac{1}{\sqrt{p_{a_{prev}}}}-\frac{1}{\sqrt{p_{a_{current}}}}) o ff se t e t h ← o ff se t e t h + 2 a s q u a r t ( p a p re v 1 − p a c u rre n t 1 )
o f f s e t u s d c ← o f f s e t u s d c + a s q u a r t 2 ( p b p r e v − p b c u r r e n t ) offset_{usdc} ← offset_{usdc} + \frac{a_{squart}}{2}(\sqrt{p_{b_{prev}}}-\sqrt{p_{b_{current}}}) o ff se t u s d c ← o ff se t u s d c + 2 a s q u a r t ( p b p re v − p b c u rre n t )
The interest payments that occur while the protocol is shouldering the debt accumulate as ReallocationFeeGrowth.
Copy 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.
Copy //
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
Copy //
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
m i n V a l u e W i t h i n R a n g e = m i n ( v ( p R ) , v ( p R ) ) minValueWithinRange =min(v(pR), v(\frac{p}{R})) minVa l u e Wi t hin R an g e = min ( v ( pR ) , v ( R p ))
m i n D e p o s i t = P o s i t i o n V a l u e − m i n V a l u e W i t h i n R a n g e minDeposit = PositionValue - minValueWithinRange min De p os i t = P os i t i o nVa l u e − minVa l u e Wi t hin R an g e
Where, R = risk params and it sets as 1.2.
Liquidation Price
Find √X satisfy v x = m i n D e p o s i t v_x = minDeposit v x = min De p os i t
x 1 = ( − a s q u a r t + a s q u a r t 2 − a p e r p ∗ ( − e n t r y p e r p − e n t r y p e r p + m ) ) ∗ R 2 a p e r p \sqrt{x_1}=\frac{(-a_{squart}+\sqrt{a_{squart}^2-a_{perp}*(-entry_{perp}-entry_{perp}+m)}) * \sqrt{R}}{2a_{perp}} x 1 = 2 a p er p ( − a s q u a r t + a s q u a r t 2 − a p er p ∗ ( − e n t r y p er p − e n t r y p er p + m ) ) ∗ R
x 2 = ( − a s q u a r t − a s q u a r t 2 − a p e r p ∗ ( − e n t r y p e r p − e n t r y p e r p + m ) ) 2 a p e r p ∗ R \sqrt{x_2}=\frac{(-a_{squart}-\sqrt{a_{squart}^2-a_{perp}*(-entry_{perp}-entry_{perp}+m)})}{2a_{perp} * \sqrt{R}} x 2 = 2 a p er p ∗ R ( − a s q u a r t − a s q u a r t 2 − a p er p ∗ ( − e n t r y p er p − e n t r y p er p + m ) )
Margin Available
V a u l t V a l u e = M a r g i n + P o s i t i o n V a l u e Vault Value = Margin + Position Value Va u lt Va l u e = M a r g in + P os i t i o nVa l u e
M a r g i n U t i l i z i n g = M i n . D e p o s i t Margin Utilizing = Min. Deposit M a r g in U t i l i z in g = M in . De p os i t
M a r g i n A v a i l a b l e = V a u l t V a l u e − M a r g i n U t i l i z i n g MarginAvailable = VaultValue - Margin Utilizing M a r g in A v ai l ab l e = Va u lt Va l u e − M a r g in U t i l i z in g
W i t h d r a w − a b l e M a r g i n = m i n ( M a r g i n A v a i l a b l e , M a r g i n ) Withdraw-ableMargin=min(MarginAvailable, Margin) Wi t h d r a w − ab l e M a r g in = min ( M a r g in A v ai l ab l e , M a r g in )