Long and short

All amounts in USDC have 6 decimals. Leverage is passed in basis points (10,000 = 1x).

Opening a long

openLong(marketId, margin, leverageBps, minCoinOut)

  1. The contract records a fresh observation of both pools and checks the spot is within 5% of the oracle.
  2. It borrows margin * (leverage - 1) USDC from the market's USDC pool.
  3. It takes the 0.10% opening fee from the margin, then swaps the rest of the margin plus the loan: USDC to HYPE in the HYPE/USDC pool, HYPE to the coin in the coin's pool.
  4. The swap must fill within the execution band of the oracle price (pool fees, plus 0.30%, plus 10%), and above minCoinOut.
  5. The coin stays in the contract as collateral. The USDC debt grows with the pool's borrow index.

Opening a short

openShort(marketId, margin, leverageBps, minUsdcOut)

  1. Same checks as a long.
  2. It borrows coins worth margin * (leverage - 1) at the oracle price from the market's coin pool.
  3. It sells them for USDC through the same two pools, in the other direction.
  4. Margin plus proceeds stay as USDC collateral. The coin debt grows with the coin pool's borrow index.

An open also needs a cover of at least 110% after costs, the position under the coin's size cap and the side under its open interest cap.

Closing

close(positionId, limit)

  • A long sells all its coins back to USDC, repays the debt with interest and sends the rest to the owner. limit is the minimum USDC out.
  • A short buys back exactly the coin debt with its USDC, repays it and sends the rest. limit is the maximum USDC in.
  • Pass 0 for no limit. Only the owner can close, at any time, without the keeper.

Adding margin

addMargin(positionId, amount) adds USDC. On a long it repays debt; on a short it adds collateral. Either way the cover goes up.