Long/Short Symmetry
Long and short are naturally supported by swapping either
token0totoken1, ortoken1totoken0. 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,liquidityand swap calldatadatacan cover all 4 cases:long
token0usingtoken1:marginFromistoken1,datainstructs swappingtoken1totoken0long
token1usingtoken0:marginFromistoken0,datainstructs swappingtoken0totoken1short
token0usingtoken1:marginToistoken1,datainstructs swappingtoken0totoken1short
token1usingtoken0:marginToistoken0,datainstructs swappingtoken1totoken0
At position closing, the
repayFromandrepayToare the amounts to pay back to LP position such that at least the borrowed liquidity is repaid to LP position. TheamountSwaphow much of position and premium amount we swap back.In the case of long ETH with USDC, the
amountSwapswaps all ETH back to USDC, only leaving enough ETH to repay to LP.In the case of short ETH with USDC, the
amountSwaponly swaps just enough USDC into ETH to repay, with the rest USDC as gains to trader.
Last updated