Long/Short Symmetry

  • Long and short are naturally supported by swapping either token0 to token1, or token1 to token0. 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 calldata data can cover all 4 cases:

    • long token0 using token1: marginFrom is token1, data instructs swapping token1 to token0

    • long token1 using token0: marginFrom is token0, data instructs swapping token0 to token1

    • short token0 using token1 :marginTo is token1, data instructs swapping token0 to token1

    • short token1 using token0 :marginTo is token0, data instructs swapping token1 to token0

  • At position closing, the repayFrom and repayTo are the amounts to pay back to LP position such that at least the borrowed liquidity is repaid to LP position. The amountSwap 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