Deposits

Four‑step journey to convert user tokens into interest‑bearing tHLP shares.


Key On‑Chain State

MIN_DEPOSITuint64

Minimum notional deposit in μ‑USDC (1,000,000 μ = 1 USDC).

depmapping(address ⇒ Dep)

Tracks each user’s in‑flight deposit: how much USDC was bridged, which Core tokenId, core decimals, helper address & stage.

Depstruct

{ uint64 amt; uint64 collateral; uint256 preEq; uint32 tokenId; address helper; DepStage st; } — see enum DepStage for workflow stage.

depositCollateral

Step 1: Transfer your ERC‑20 into THLP, bridge it into a cloned OrderHelper, and place a Core limit‑sell order.

depositCollateral.sol
function depositCollateral(
  address token,
  address sys,
  uint32 index,
  uint256 amountNtl,
  uint8 coreDec,
  uint64 tokenId,
  uint16 slippageBps
) external nonReentrant;
  • Reverts if amountNtl == 0 or < MIN_DEPOSIT, or if you already have a pending deposit.
  • Reads ERC‑20 decimals ⇒ evmDec; computes amtEvmWei = amountNtl × 10^evmDec (your on‑chain token units).
  • Computes amtCoreWei = amountNtl × 10^coreDec (Core’s token units), then transferFrom → THLP → Core sys address.
  • Clones a fresh OrderHelper, pre‑funds it via sendSpotSend(coreTokenId, amtCoreWei) and then calls placeOrder().
  • Your `slippageBps` is the maximum deviation from mid‑price you’ll accept: limitPx = midPx × (10 000 – slippageBps) / 10 000.
  • Typically your UI will fetch the current best bid/ask, compute a small slippage tolerance (e.g. 5–50 bps), and pass it in automatically.
  • Stores Dep({ amt: 0, collateral: amtCoreWei, …, helper, st: BRIDGED }) and emits DepositStarted.

depositConfirmAndDeposit

Step 2: Once Core fills your order, sweep back USDC, deduct any deposit fee, and enqueue into the current epoch bucket in the HyperLiquid vault.

depositConfirmAndDeposit.sol
function depositConfirmAndDeposit() external nonReentrant;
  • Requires dep[msg.sender].st == BRIDGED.
  • OrderHelper.sweepFilled() ⇒ filledUsdc; split out fee with _splitFee; send fee to owner if enabled.
  • Set dep[msg.sender].amt = net, totalDeposits += net.
  • Call _activeBucket() to clone or reuse a bucket helper, sendSpotSend(USDC_ID, net), then vaultDeposit(vault, net ÷ 1e6).
  • Mark dep[msg.sender].st = FINALIZED and emit VaultDepositEnqueued.

depositFinalize

Step 3: Once the HyperLiquid vault equity has updated, mint your tHLP shares pro‑rata and clear your pending state.

depositFinalize.sol
function depositFinalize() external;
  • Requires dep[msg.sender].st == FINALIZED.
  • Optionally verify vaultEquity > preEq to guard against failed deposits.
  • Compute shares = _convertToShares(dep[msg.sender].amt, totalSupply()).
  • Mint those shares, delete dep[msg.sender], and emit DepositFinalized.

refundCollateral

Cancel your in‑flight deposit if your Core limit order never fills (or you change your mind).

refundCollateral.sol
function refundCollateral() external nonReentrant;
  • Requires dep[msg.sender].st == BRIDGED.
  • Calls OrderHelper.sweepBackBase(tokenId) to retrieve any unsold base tokens from Core.
  • Forwards that amount back to you via sendSpotSend, then deletes dep[msg.sender].
  • You’ll get 100 % of your original collateral back—no fees are taken on refunds.