Long/Short Symmetry
Long and short are naturally supported by swapping either
token0
totoken1
, ortoken1
totoken0
. It’s worth noting that the margin payment can be the token we swap from or swap to.For example, when we long ETH using USDC, we swap the margin and borrowed USDC into ETH. In this case, USDC is the token we swap from in this case.
On the other hand, if we short ETH using USDC, it’s swapping the borrowed ETH to USDC (long USDC). In this case, we put down USDC as the margin payment. USDC is the token we swap to in this case.
At position opening, the
marginFrom
,marginTo
,liquidity
and swap calldatadata
can cover all 4 cases:long
token0
usingtoken1
:marginFrom
istoken1
,data
instructs swappingtoken1
totoken0
long
token1
usingtoken0
:marginFrom
istoken0
,data
instructs swappingtoken0
totoken1
short
token0
usingtoken1
:marginTo
istoken1
,data
instructs swappingtoken0
totoken1
short
token1
usingtoken0
:marginTo
istoken0
,data
instructs swappingtoken1
totoken0
At position closing, the
repayFrom
andrepayTo
are the amounts to pay back to LP position such that at least the borrowed liquidity is repaid to LP position. TheamountSwap
how much of position and premium amount we swap back.In the case of long ETH with USDC, the
amountSwap
swaps all ETH back to USDC, only leaving enough ETH to repay to LP.In the case of short ETH with USDC, the
amountSwap
only swaps just enough USDC into ETH to repay, with the rest USDC as gains to trader.
Last updated