Hyperliquid 백서

Hyperliquid

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 27쪽 중 6쪽

s margin only applies to the assets within the same DEX. See [here](/hyperliquid-docs/trading/account-abstraction-modes) for more details. HIP-3 DEXs also support "no cross" margin mode, which allows isolated margin with margin removal enabled, but does not allow cross margin.&#x20; ### Initial Margin and Leverage Leverage can be set by a user to any integer between 1 and the max leverage. Max leverage depends on the asset.&#x20; The margin required to open a position is `position_size * mark_price / leverage`. The initial margin is used by the position and cannot be withdrawn for cross margin positions. Isolated positions support adding and removing margin after opening the position. Unrealized pnl for cross margin positions will automatically be available as initial margin for new positions, while isolated positions will apply unrealized pnl as additional margin for the open position.\ \ The leverage of an existing position can be increased without closing the position. Leverage is only checked upon opening a position. Afterwards, the user is responsible for monitoring the leverage usage to avoid liquidation. Possible actions to take on positions with negative unrealized pnl include partially or fully closing the position, adding margin (if isolated), and depositing USDC (if cross). ### Unrealized PNL and transfer margin requirements Unrealized pnl can be withdrawn from isolated positions or cross account, but only if the remaining margin is at least 10% of the total notional position value of all open positions. The margin remaining must also meet the initial margin requirement, i.e. `transfer_margin_required = max(initial_margin_required, 0.1 * total_position_value)`&#x20; Here, "transferring" includes any action that removes margin from a position, other than trading. Examples include withdrawals, transfer to spot wallet, and isolated margin transfers. ### Maintenance Margin and Liquidations Cross positions are liquidated when the account value (including unrealized pnl) is less than the *maintenance margin* times the total open notional position. The maintenance margin is currently set to half of the initial margin at max leverage.&#x20; Isolated positions are liquidated by the same maintenance margin logic, but the only inputs to the computation are the isolated margin and the notional value of the isolated position. # Account abstraction modes A user's *account abstraction mode* determines how spot and perps balances interact, and whether various assets are used as collateral for perps trading.&#x20; The supported modes are: 1. Unified account (recommended for most users): single balance for each asset. This balance collateralizes all cross margin positions in that asset and is unified with spot balance in that asset. For example, USDC balance is the single source for validator-operated perps, XYZ perps, and spot trading against USDC as a quote asset. USDT spot balance is the single source for CASH perps and spot trading against USDT as a quote asset.&#x20; 2. Portfolio margin (most capital efficient): single portfolio unifying all eligible assets, which are currently HYPE, BTC, USDC, USDT. See [Portfolio margin](/hyperliquid-docs/trading/portfolio-margin) for more details.&#x20; 3. Manual / Standard (recommended for market makers, high volume automated users, and deployers/builders): separate perp and spot balances, separate DEX balances. Cross margin applies to each DEX separately.&#x20; There is one more mode that was discontinued, included here for completeness: 4. DEX abstraction (discontinued): USDC balances default to perps balance, all other collateral defaults to spot balance. IMPORTANT: Cross margin on HIP-3 DEXs does not behave intuitively for DEX abstraction users.&#x20; Important details: 1. Builder code addresses must be in standard mode to accrue builder fees 2. Portfolio margin and unified account are limited to 50k user actions per day. Standard mode has no such restrictions. 3. For API users, unified account and portfolio margin show all balances and holds in the spot clearinghouse state. Individual perp dex user states are not meaningful. &#x20; See Python SDK and [API docs](/hyperliquid-docs/for-developers/api) for examples on the agent- and user-signed actions for changing account abstraction modes. &#x20; ### Unified Account Ratio To compute the precise unified account ratio for monitoring liquidation risk: ```typescript function computeUnifiedAccountRatio( multiverse: Record<string, { index: number; collateralToken: number }>, perpDexStates: Array<{ clearinghouseState: { crossMaintenanceMarginUsed: number; assetPositions: Array<{ position: { leverage: { type: string }; marginUsed: number }; }>; }; }>, spotBalances: Array<{ token: number; total: number }>, ): number { const indexToCollateralToken: Record<number, number> = {}; for (const meta of Object.values(multiverse)) { indexToCollateralToken[meta.index] = meta.collateralToken; } const crossMarginByToken: Record<number, number> = {}; const isolatedMarginByToken: Record<number, number> = {}; for (let index = 0; index < perpDexStates.length; index++) { const dex = perpDexStates[index]; const token = indexToCollateralToken[index]; if (dex === undefined || token === undefined) continue; crossMarginByToken[token] = (crossMarginByToken[token] ?? 0) + dex.clearinghouseState.crossMaintenanceMarginUsed; for (const ap of dex.clearinghouseState.assetPositions) { if (ap.position.leverage.type === "isolated") { isolatedMarginByToken[token] = (isolatedMarginByToken[token] ?? 0) + ap.position.marginUsed; } } } let maxRatio = 0; for (const [tokenStr, crossMargin] of Object.entries(crossMarginByToken)) { const token = Number(tokenStr); const spotTotal = spotBalances.find((b) => b.token === token)?.total ?? 0; const isolatedMargin = isolatedMarginByToken[token] ?? 0; const available = spotTotal - isolatedMargin; if (available > 0) { maxRatio = Math.max(maxRatio, crossMargin / available); } } return maxRatio; } ``` # Portfolio margin Under portfolio margin, a user’s spot and perps trading are unified for greater capital efficiency. Furthermore, portfolio margin accounts automatically earn yield on all borrowable assets not actively used for trading. Portfolio margin unlocks functionality such as the carry trade where a spot balance is offset by a short perps position, collateralized by the spot balance. Spot and perp pnl offset each other, protecting against liquidation on the perp position. More generally, spot and perps trading can be performed from a single unified balance. For example, a user could also hold HYPE and immediately buy BTC on the BTC/USDC book. All HIP-3 DEXs are included in portfolio margin, though not all HIP-3 DEX collateral assets are borrowable. Future HyperCore asset classes and primitives will support portfolio margin as well. Users can supply eligible quote assets to earn yield. This synergizes and composes with HyperEVM lending protocols. In a future upgrade, CoreWriter will expose the same supply action for smart contracts. Portfolio margin intentionally does not bring a full-fledged lending market to HyperCore, as that is best built by independent teams on the EVM. For example, HyperCore lending is not tokenized, but an EVM protocol could do so by launching a fully onchain yield-bearing ERC20 token contract through CoreWriter and precompiles. Portfolio margin introduces organic demand to borrow and should expand the value proposition of teams building on the HyperEVM. IMPORTANT: Portfolio margin is a complex technical upgrade and requires bootstrapping the supply side for borrowable assets. Portfolio margin accounts will fall back to non-portfolio margin behavior when caps are hit. The following requirements apply:&#x20; * Master account >$5M in weighted volume or account value >$10k * Account value <$25M * USDT: 50M USDT global supply cap, 10M USDT global borrow cap, 5M USDT user supply cap, 1M USDT user borrow cap * USDC: 1B USDC global supply cap, 500M USDC global borrow cap, 250M USDC user supply cap, 50M USDC user borrow cap * HYPE: 25M HYPE global supply cap, 1M HYPE user supply cap * BTC: 5k BTC global supply cap, 200 BTC user supply cap ### LTV and borrowing Under portfolio margin, eligible collateral assets have an LTV (loan-to-value) ratio between 0 and 1. HYPE has an LTV of 0.65 and BTC has an LTV of 0.5. When placing spot and perp orders under portfolio margin, insufficient balance will automatically borrowed against eligible collateral up to `token_balance * borrow_oracle_price * ltv` , where price is denominated in the asset being borrowed. Borrowed assets accrue interest continuously, and are indexed hourly to match the perp funding interval. Portfolio margin users pay interest on borrowed assets and earn interest on idle assets according to the same rate. The borrow interest rate for stablecoins is set at `0.05 + 4.75 * max(0, utilization - 0.8)` APY, compounded continuously depending on the instantaneous value of `utilization = total_borrowed_value / total_supplied_value` . Earned interest is accrued proportionally to all suppliers. The protocol retains 10% of borrowed interest as a buffer for future liquidations. ### Example: Carry trade The carry trade becomes significantly more capital efficient with portfolio margin, as there is no trading cost to rebalance over signifcant price ranges. A portfolio margin account's spot borrow and perps pnl offset each other for accounting. The trader still needs to account for external factors such as funding, interest, and drift between spot and perp prices. For example, a user holds 1 BTC in spot and shorts 1 BTC-USDC perp at 10x leverage. If BTC's price is 100k, the user only pays interest on the 1/10 initial margin but earns funding on the full 100k position. If BTC's price moves down to 50k, the trader has unrealized pnl in USDC. The trader can choose to maintain the notional value of the trade by buying more spot BTC and increasing the perp short. If BTC's price moves up to 150k, portfolio margin automatically borrows 50k USDC against the spot BTC, now worth 150k. The user can sell BTC and close the perp position to maintain the notional exposure of the funding trade. If BTC's price moves up to 200k, the trader must reduce the notional exposure of the funding trade to avoid a borrow-lend liquidation. Note that the hedged price range increased dramatically compared to the same trade without portfolio margin, where the perp leg is collateralized by USDC. &#x20; ### Liquidations Portfolio margin is a generalization of cross margin. Instead of margining all perp positions within one DEX together, all cross margin perp positions and spot balances are collectively margined together within one account. Sub-accounts are still treated separately under portfolio margin.&#x20; Liquidations are triggered when the entire portfolio margin account is below its portfolio maintenance margin requirement. Users can monitor this requirement via the *portfolio margin ratio,* defined as {% code overflow="wrap" %} ```latex portfolio_margin_ratio = max_{borrowable_token} (portfolio_maintenance_requirement(borrowable_token) / portfolio_liquidation_value(borrowable_token)) where portfolio_maintenance_requirement(token) = min_borrow_offset + sum_{dex} cross_maintenance_margin(dex) + borrowed_size_for_maintenance(token) * borrow_oracle_price(token) portfolio_liquidation_value(token) = portfolio_balance(token) + min(borrow_cap(token), min(portfolio_balance(token), supply_cap(token)) * borrow_oracle_price(token) * liquidation_threshold(token)) liquidation_threshold(token) = 0.5 + 0.5 * LTV(token) borrow_oracle_price(token) = median(HL_spot_USDC_price, HL_perp_mark_price * USDT_USDC_oracle, HL_perp_oracle_price * USDT_USDC_oracle) USDT_USDC_oracle = 1 / HL_spot_oracle_price(USDC) min_borrow_offset = 20 USDC ``` {% endcode %} The account becomes liquidatable when portfolio\_margin\_ratio > 0.95. All notional values in the above definition are converted to USDC using `borrow_oracle_price(token)` . After borrow caps are hit, additional margin used must be supplied by the user using the settlement asset regardless of whether portfolio margin is active.&#x20; Depending on the order of oracle price updates, either perp positions or spot borrows may be liquidated first. In other words, once portfolio margin ratio is liquidatable, users should not expect a deterministic liquidation sequence. Portfolio margin liquidations are taken over directly by the backstop liquidator at system address `0xbbb...b` . If the user health is below the full liquidation threshold, the supplied assets with positive LTV and borrowed assets are fully taken over by the backstop liquidator. If the user health is between the partial liquidation and full liquidation threshold, supplied assets with positive LTV and borrowed assets are instead taken over in 20% intervals, stopping as soon as the user is no longer liquidatable. The slippage threshold for takeover is `size_liquidated * oracle_price * (LTV(asset) + 2) / 3) * width` where width is `3M USDC` for HYPE and `300k USDC` for BTC. The backstop liquidator converts collateral assets to debt assets for repayment, using a TWAP with a half life of 10 minutes. Unlike perps, there is no market liquidation phase, as spot books have less consistent liquidity than perps. # Margin tiers Like most centralized exchanges, the tiered leverage formula on Hyperliquid is as follows: `maintenance_margin = notional_position_value * maintenance_margin_rate - maintenance_deduction`&#x20; On Hyperliquid, `maintenance_margin_rate` and `maintenance_deduction` depend only on the margin tiers, not the asset. `maintenance_margin_rate(tier = n) = (Initial Margin Rate at Maximum leverage at tier n) / 2` . For example, at 20x max leverage, `maintenance_margin_rate = 2.5%`. Maintenance deduction is defined at each tier to account for the different maintenance margin rates used at previous tiers: `maintenance_deduction(tier = 0) = 0` &#x20; `maintenance_deduction(tier = n) = maintenance_deduction(tier = n - 1) + notional_position_lower_bound(tier = n) * (maintenance_margin_rate(tier = n) - maintenance_margin_rate(tier = n - 1))` for `n > 0`&#x20; In other words, maintenance deduction is defined so that new positions opened at each tier increase maintenance margin at `maintenance_margin_rate` , while having the total maintenance margin be a continuous function of position size. Margin tables have unique IDs and the tiers can be found in the `meta` Info response. For IDs less than 50, there is a single tier with max leverage equal to the ID. ### Mainnet Margin Tiers Mainnet margin tiers are enabled for the assets below: #### BTC | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-150M | 40 | | >150M | 20 | #### ETH | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-100M | 25 | | >100M | 15 | #### SOL | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-70M | 20 | | >70M | 10 | #### XRP | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-40M | 20 | | >40M | 10 | #### AAVE, ADA, APT, AVAX, BCH, CRV, DOGE, ENA, FARTCOIN, HYPE, kBONK, kPEPE, LINK, LTC, NEAR, PUMP, SUI, TRUMP, UNI, WLD, ZEC | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-20M | 10 | | >20M | 5 | #### ARB, BNB, DOT, JUP, kSHIB, MKR, ONDO, PAXG, TON, TRX, XPL | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-3M | 10 | | >3M | 5 | ### Testnet Margin Tiers The tiers on testnet are lower than mainnet, for ease of testing.&#x20; #### ARB, ATOM, AVAX, FARTCOIN, ICP, TAO - testnet only | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-10k | 10 | | >10k | 5 | #### DOGE, TIA, SUI, kSHIB, AAVE, TON - testnet only | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-20k | 10 | | >20k | 5 | #### ETH - testnet only | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-20k | 25 | | 20-50k | 10 | | >50k | 5 | #### BTC - testnet only | Notional Position Value (USDC) | Max Leverage | | ------------------------------ | ------------ | | 0-10k | 40 | | 10-50k | 25 | | >50k | 10 | # Robust price indices Hyperliquid makes use of several robust prices based on order book and external data to minimize risk of market manipulation. *Oracle price* is used to compute funding rates. This weighted median of CEX prices is robust because it does not depend on hyperliquid's market data at all. Oracle prices are updated by the validators approximately once every three seconds. *Mark price* is the median of the following prices: 1. Oracle price plus a 150 second exponential moving average (EMA) of the difference between Hyperliquid's mid price and the oracle price 2. The median of best bid, best ask, last trade on Hyperliquid 3. Median of Binance, OKX, Bybit, Gate IO, MEXC perp mid prices with weights 3, 2, 2, 1, 1, respectively If exactly two out of the three inputs above exist, the 30 second EMA of the median of best bid, best ask, and last trade on Hyperliquid is also added to the median inputs. Mark price is an unbiased and robust estimate of the fair perp price, and is used for margining, liquidations, triggering TP/SL, and computing unrealized pnl. Mark price is updated whenever validators publish new oracle prices. Therefore, mark and oracle price are updated approximately once every 3 seconds. The EMA update formula is defined as follows for an update value of `sample` at duration `t` since the last update `ema = numerator / denominator` `numerator -> numerator * exp(-t / 2.5 minutes) + sample * t`&#x20; `denominator -> denominator * exp(-t / 2.5 minutes) + t` # Liquidations ### Overview A liquidation event occurs when a trader's positions move against them to the point where the account equity falls below the maintenance margin. The maintenance margin is half of the initial margin at max leverage, which varies from 3-40x. In other words, the maintenance margin is between 1.25% (for 40x max leverage assets) and 16.7% (for 3x max leverage assets) depending on the asset. When the account equity drops below maintenance margin, the positions are first attempted to be entirely closed by sending market orders to the book. The orders are for the full size of the position, and may be fully or partially closed. If the positions are entirely or partially closed such that the maintenance margin requirements are met, any remaining collateral remains with the trader. If the account equity drops below 2/3 of the maintenance margin without successful liquidation through the book, a backstop liquidation happens through the liquidator vault. See Liquidator Vault explanation below for more details. When a cross position is backstop liquidated, the trader's cross positions and cross margin are all transferred to the liquidator. In particular, if the trader has no isolated positions, the trader ends up with zero account equity. When an isolated position is backstop liquidated, that isolated position and isolated margin are transferred to the liquidator. The user's cross margin and positions are untouched. During backstop liquidation, the maintenance margin is not returned to the user. This is because the liquidator vault requires a buffer to make sure backstop liquidations are profitable on average. In order to avoid losing the maintenance margin, traders can place stop loss orders or exit the positions before the mark price reaches the liquidation price. Liquidations use the
프로젝트로 돌아가기