Hyperliquid 백서

Hyperliquid

원문

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

-0.01 and 0.01 and are used as the interest rate * component in the funding calculation. */ type SetFundingInterestRates = Array<[string, string]>; /** * A sorted list of asset and 8 hour funding clamp. * Clamps must be between 0 and 0.01 and bound how far the funding rate can move away from the * average premium toward the interest rate. Defaults to 0.0003. */ type SetFundingClamps = Array<[string, string]>; /** * A sorted of asset and margin table ids. * Margin table ids must be non-zero. */ type SetMarginTableIds = Array<[string, number]>; /** * Inserts margin table to dex */ type InsertMarginTable = { dex: string; marginTable: RawMarginTable; }; /** * marginTiers must be sorted in order of increasing lower bound and decreasing maxLeverage * marginTiers has a maximum length of 3. */ type RawMarginTable = { description: string; marginTiers: Array<RawMarginTier>; }; /** * lowerBound is a position notional value above which the leverage is constrained by maxLeverage */ type RawMarginTier = { lowerBound: int; maxLeverage: MaxLeverage; }; /** * Max leverage is in the range [1, 50] */ type MaxLeverage = number; /** * A sorted list of asset and open interest cap notionals. * Open interest caps must be at least the maximum of 1_000_000 (1 size unit of collateral asset) or half of the current open interest. * null removes the custom cap for an asset. */ type SetOpenInterestCaps = Array<[string, number | null]>; /** * A modification to sub-deployer permissions */ type SubDeployerInput = { variant: string; // corresponds to a variant of PerpDeployAction. For example, "haltTrading" or "setOracle" user: String; allowed: boolean; // add or remove the subDeployer from the authorized set for the action variant }; // A sorted list of (coin, marginMode). See RegisterAssetRequest2 for margin mode definitions. type SetMarginModes = Array<[string, "strictIsolated" | "noCross" | "normal"]>; // Let the user normal rate be `x`. Let the user rate be `y` after accounting for aligned quote collateral. // In other words, `x = y` for non-aligned collateral. // User pays or receives rebate `P + D` where `P` goes to protocol and `D` goes to deployer. // If `x > 0` and `scale < 1`, `P = y` and `D = scale * x` // If `x > 0` and `scale > 1`, `P = y * scale` and `D = x * scale` // If `x < 0` and `scale < 1`, `P = y / (1 + scale)` and `D = y * scale / (1 + scale)` // If `x < 0` and `scale > 1`, `P = y / 2` and `D = y / 2` // On Mainnet, rate limited to one change per 30 days. // Note that there are currently no aligned quote assets on mainnet. type SetDeployerFees = Array< [ string, { scale: string; // Decimal string in [0.0, 3.0], or [0.0, 10.0) when growthMode is true growthMode: boolean; }, ] >; // category <= 15 characters // description <= 400 characters // displayName <= 9 characters // <= 2 keywords, each keyword <= 10 characters type SetPerpAnnotation = { coin: string; category: string; description: string; displayName: string | null; keywords: Array<string>; }; ``` For the following examples, `feeScale` is the `scale` field in `SetDeployerFees`. Assume a positive normal user fee of 1 unit and non-aligned collateral (`x = y = 1`). `userFeeToProtocol` and `userFeeToDeployer` are the resulting fee units charged to the user. | `growthMode` | `feeScale` | `userFeeToProtocol` | `userFeeToDeployer` | | ------------ | ---------- | ------------------- | ------------------- | | `false` | `"0"` | `1` | `0` | | `false` | `"0.5"` | `1` | `0.5` | | `false` | `"1"` | `1` | `1` | | `false` | `"3"` | `3` | `3` | | `true` | `"0"` | `0.1` | `0` | | `true` | `"0.5"` | `0.1` | `0.05` | | `true` | `"1"` | `0.1` | `0.1` | | `true` | `"3.01"` | `0.301` | `0.301` | | `true` | `"9.99"` | `0.999` | `0.999` | See <https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-information-about-the-perp-deploy-auction> for how to query for the perp deploy auction status. #### Open interest caps Builder-deployed perp markets are subject to two types of open interest caps: notional (sum of absolute position size times mark price) and size (sum of absolute position sizes). Notional open interest caps are enforced on the total open interest summed over all assets within the DEX, as well as per-asset. Perp deployers can set a custom open interest cap per asset, which is documented in <https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/hip-3-deployer-actions>. Size-denominated open interest caps are only enforced per-asset. Size-denominated open interest caps are currently a constant 1B per asset, so a reasonable default would be to set `szDecimals` such that the minimal size increment is $1-10 at the initial mark price. #### Backstop liquidator The backstop liquidator address is `0x4000000000000000000000000000000000000000 + {dex_index}`. For example, the first HIP-3 DEX has backstop liquidator address `0x4000000000000000000000000000000000000001`. #### Node user account summaries The node flag `--write-user-account-summaries <dex>` writes account summaries for the named HIP-3 DEX to hourly files at `~/hl/data/dex_user_account_summaries/hourly/<date>/<hour>`, where `date` is `YYYYMMDD`. Each line is a JSON array `[time, messages]`, where `time` is the block time and `messages` is either a single snapshot of every user on the DEX or a list of per-user diffs: ```json ["2026-09-24T09:00:00.123", [{ "Snapshot": { "0xUSER_A": { "a": "100.0", "b": "90.0" } } }]] ["2026-09-24T09:00:03.456", [{ "Diff": ["0xUSER_A", { "a": "105.0", "b": "90.0" }] }]] ``` `a` is account value and `b` is `balance = accountValue - unrealizedPnl`, both denominated in the venue's collateral token. The first line of each file, and the first line written after the node starts, is a snapshot. Other lines contain diffs for users whose summary changed: every such user on an oracle update for the venue, or only the users involved in a fill, liquidation, funding payment, or transfer into or out of the venue. ## HIP-3\* (testnet-only) ### Star actions A HIP-3 venue can be designated HIP-3\* at time of creation by setting `isStar: true` in `PerpDexSchemaInput`. This optional boolean defaults to `false`. HIP-3\* enables several features on top of the HIP-3 spec, including an allow-list and proxied user actions. #### Operations ```typescript type Hip3StarAction = { type: "perpDeploy"; star: { dex: string; operation: Hip3StarOperation }; }; type Hip3StarOperation = | { proxy: [address, Hip3StarProxyOperation] } | { setOracle: { oraclePxs: Array<[string, string]> } }; // CancelAction and OrderAction are the standard exchange actions. type Hip3StarProxyOperation = | { modifyApproval: boolean } | { modifyBackstopLiquidatorApproval: boolean } | { setReduceOnly: boolean } | { cancel: Omit<CancelAction, "type"> } | { cancelAll: { assets?: Array<number> | null } } | { order: Omit<OrderAction, "type"> } | { sendAsset: { destination: address; amount: string } }; ``` ```json { "type": "perpDeploy", "star": { "dex": "test", "operation": { "proxy": ["0xUSER_A", { "modifyApproval": true }] } } } { "type": "perpDeploy", "star": { "dex": "test", "operation": { "proxy": ["0xUSER_B", { "cancelAll": { "assets": [100001, 100002] } }] } } } { "type": "perpDeploy", "star": { "dex": "test", "operation": { "setOracle": { "oraclePxs": [["test:BTC", "100000.0"], ["test:ETH", "4000.0"]] } } } } ``` * **`proxy`** — a pair of a user address and one proxy operation applied to that user. * **`setOracle`** — updates oracle prices, as described under Oracle below. #### Proxy operations * **`modifyApproval`** — `{ "modifyApproval": true }` adds the user to the allowlist, `false` removes them and clears their flags. Removing a user who is not approved is a no-op. Re-approving an approved user is a no-op and keeps the user's flags. A removed user who is approved again starts with default flags. * **`modifyBackstopLiquidatorApproval`** — `{ "modifyBackstopLiquidatorApproval": true }` allows the user to deposit into and withdraw from the venue's backstop liquidator via `hip3LiquidatorTransfer`; `false` revokes this. The user must already be approved via `modifyApproval`. * **`setReduceOnly`** — `{ "setReduceOnly": true }` restricts an approved user to reducing their positions on the venue. The user can only place reduce-only orders and TWAPs, modify orders into reduce-only orders, and cancel. `{ "setReduceOnly": false }` restores full trading. * **`cancel`** — `{ "cancel": { "cancels": [{ "a": <asset>, "o": <oid> }] } }`, the standard `cancel` exchange-action payload. Cancels the user's resting orders by oid. * **`cancelAll`** — `{ "cancelAll": { "assets": null } }` cancels all of the user's resting orders and TWAPs on this venue. `{ "cancelAll": { "assets": [<asset>, ...] } }` cancels only the user's resting orders and TWAPs for the listed assets. The list must contain 1-10 entries. * **`order`** — `{ "order": { "orders": [...], "grouping": "na" } }`, the standard `order` exchange-action payload. Every order must be reduce-only (`"r": true`). * **`sendAsset`** — `{ "sendAsset": { "destination": "0xUSER_C", "amount": "100.0" } }`. Moves collateral from the proxied user's account on the DEX to `destination`'s account on the same venue. #### Oracle HIP-3\* venues update prices with the `setOracle` star operation deploy action. `oraclePxs` is a list (sorted by key) of asset and spot oracle prices. External perp prices and mark prices are derived onchain based on the deployer's spot oracle price inputs. * **External perp prices** are derived from the main dex asset with the same name, with the denomination converted to USDC. For example, `test:BTC` uses the external perp price of `BTC`. * **Mark prices** are computed onchain as the median of: 1. the oracle price adjusted by an exponential moving average of the mid price's premium over the oracle price, 2. the external perp price, and 3. the local mark price (median(best bid, best ask, last trade price)). If only two of these prices are available, an exponential moving average of the local mark price is added as a third input. #### Permissions For HIP-3\*, `SubDeployerInput.variant` also accepts the objects shown below. | Operation | Deployer | Sub-deployer grant | | ---------------------------------- | -------- | ---------------------------------------------------- | | `modifyApproval` | yes | `{ "hip3Star": "modifyApproval" }` | | `modifyBackstopLiquidatorApproval` | yes | `{ "hip3Star": "modifyBackstopLiquidatorApproval" }` | | `setReduceOnly` | yes | `{ "hip3Star": "setReduceOnly" }` | | `cancel` | yes | `{ "hip3Star": "cancel" }` | | `cancelAll` | yes | `{ "hip3Star": "cancelAll" }` | | `order` | yes | `{ "hip3Star": "order" }` | | `sendAsset` | yes | `{ "hip3Star": "sendAsset" }` | | `setOracle` | yes | `{ "hip3Star": "setOracle" }` | Each grant only covers its own operation. For example, the `modifyApproval` grant does not allow `modifyBackstopLiquidatorApproval`, `setReduceOnly`, or `sendAsset`. Likewise, the regular `"setOracle"` grant, including the one given to `oracleUpdater`, does not allow the `setOracle` star operation. ### User star state The `userStarState` info request returns a user's approval state on every HIP-3\* venue where the user has been approved. The state is `null` on venues that have since removed the user's approval. ```json { "type": "userStarState", "user": "0xUSER_A" } ``` ```json { "dexToState": { "test": { "isReduceOnly": false, "isBackstopLiquidatorDepositAllowed": true }, "demo": null } } ``` # HyperEVM The HyperEVM consists of EVM blocks built as part of Hyperliquid's execution, inheriting all security from HyperBFT consensus. HYPE is the native gas token on the HyperEVM. To move HYPE from HyperCore to HyperEVM, send HYPE to `0x2222222222222222222222222222222222222222`. See the instructions in [Native Transfers](/hyperliquid-docs/for-developers/hyperevm/hypercore-less-than-greater-than-hyperevm-transfers) for more details on how this works. Note that there are currently no official frontend components of the EVM. Users can build their own frontends or port over existing EVM applications. All interaction with the EVM happens through the JSON-RPC. For example, users can add the chain to their wallets by entering the RPC URL and chain ID. There is currently no websocket JSON-RPC support for the RPC at `rpc.hyperliquid.xyz/evm`but other RPC implementations may support it. The HyperEVM uses the Cancun hardfork without blobs. In particular, EIP-1559 is enabled on the HyperEVM. Base fees are burned as usual, implemented in the standard way where the burned fees are removed from the total EVM supply. Unlike most other EVM chains, priority fees are also burned because the HyperEVM uses HyperBFT consensus. The burned priority fees are sent to the zero address's EVM balance.&#x20; On both mainnet and testnet, HYPE on the HyperEVM has 18 decimals. A few differences between testnet and mainnet HyperEVM are highlighted below: ### Mainnet Chain ID: 999 JSON-RPC endpoint: `https://rpc.hyperliquid.xyz/evm` for mainnet&#x20; ### Testnet Chain ID: 998&#x20; JSON-RPC endpoint: `https://rpc.hyperliquid-testnet.xyz/evm` ### Additional notes Pre-EIP-155 transactions are accepted as with many EVM chains. Users generally should not use wallets that have previously sent pre-EIP-155 transactions. Error code 10055 represents errors occurring at the boundary between HyperCore and HyperEVM. Examples include nonce errors, insufficient funds, duplicate transaction hashes, or underpriced replacement transactions. # Dual-block architecture The total HyperEVM throughput is split between small blocks produced at a fast rate and large blocks produced at a slower rate.&#x20; The primary motivation behind the dual-block architecture is to decouple block speed and block size when allocating throughput improvements. Users want faster blocks for lower time to confirmation. Builders want larger blocks to include larger transactions such as more complex contract deployments. Instead of a forced tradeoff, the dual-block system will allow simultaneous improvement along both axes.&#x20; The HyperEVM "mempool" is still onchain state with respect to the umbrella L1 execution, but is split into two independent mempools that source transactions for the two block types. The two block types are interleaved with a unique increasing sequence of EVM block numbers. The onchain mempool implementation accepts only the next 8 nonces for each address. Transactions older than 1 day old in the mempool are pruned.&#x20; The initial configuration is set conservatively, and throughput is expected to increase over successive technical upgrades. Fast block duration is set to 1 seconds with a 3M gas limit. Slow block duration is set to 1 minute with a 30M gas limit.&#x20; More precisely, in the definitions above, *block duration* of `x` means that the first L1 block for each value of `l1_block_time % x` produces an EVM block.&#x20; Developers can deploy larger contracts as follows: 1. Submit action `{"type": "evmUserModify", "usingBigBlocks": true}` to direct HyperEVM transactions to big blocks instead of small blocks. Note that this user state flag is set on the HyperCore user level, and must be unset again to target small blocks. Like any action, this requires an existing Core user to send. Like any EOA, the deployer address can be converted to a Core user by receiving a Core asset such as USDC. 2. Optionally use the JSON-RPC method `bigBlockGasPrice` in place of `gasPrice` to estimate base gas fee on the next big block. # Raw HyperEVM block data Builders running a non-validating node can index the HyperEVM using data written to `~/hl/data/evm_block_and_receipts` . This data is written after committed blocks are verified by the node, and therefore has no additional trust assumptions compared to running the EVM RPC directly from the node itself. Builders that wish to index the HyperEVM without running a node can use the S3 bucket: `aws s3 ls s3://hl-mainnet-evm-blocks/ --request-payer requester`.&#x20; There is a similar bucket `s3://hl-testnet-evm-blocks/` for testnet. Builders interested in robustness can merge the two data sources, relying primarily on local data and falling back to S3 data. Some potential applications include a JSON-RPC server with custom rate limits, a HyperEVM block explorer, or other indexed services and tooling for builders. While the data is public for anyone to use, the requester must pay for data transfer costs. The filenames are predictably indexed by EVM block number, e.g. `s3://hl-mainnet-evm-blocks/0/6000/6123.rmp.lz4.` An indexer can copy block data from S3 on new HyperEVM blocks. The files are stored in MessagePack format and then compressed using LZ4. Note that testnet starts with directory `s3://hl-testnet-evm-blocks/18000000`and the earlier testnet RPC blocks were not backfilled. An example can be found in the Python SDK: <https://github.com/hyperliquid-dex/hyperliquid-python-sdk/blob/master/examples/evm_block_indexer.py> # Interacting with HyperCore ### Read precompiles The testnet EVM provides read precompiles that allows querying HyperCore information. The precompile addresses start at 0x0000000000000000000000000000000000000800 and have methods for querying information such as perps positions, spot balances, vault equity, staking delegations, oracle prices, and the L1 block number. The values are guaranteed to match the latest HyperCore state at the time the EVM block is constructed. Attached is a Solidity file `L1Read.sol` describing the read precompiles. As an example, this call queries the third perp oracle price on testnet: ``` cast call 0x0000000000000000000000000000000000000807 0x0000000000000000000000000000000000000000000000000000000000000003 --rpc-url https://rpc.hyperliquid-testnet.xyz/evm ``` To convert to floating point numbers, divide the returned price by `10^(6 - szDecimals)`for perps and `10^(8 - base asset szDecimals)` for spot. Precompiles called on invalid inputs such as invalid assets or vault address will return an error and consume all gas passed into the precompile call frame. Precompiles have a gas cost of `2000 + 65 * (input_len + output_len)`. ### CoreWriter contract A system contract is available at 0x3333333333333333333333333333333333333333 for sending transactions from the HyperEVM to HyperCore. It burns \~25,000 gas before emitting a log to be processed by HyperCore as an action. In practice the gas usage for a basic call will be \~47000. A solidity file `CoreWriter.sol` for the write system contract is attached. #### Action encoding details * Byte 1: Encoding version * Currently, only version `1` is supported, but enables future upgrades while maintaining backward compatibility. * Bytes 2-4: Action ID * These three bytes, when decoded as a big-endian unsigned integer, represent the unique identifier for the action. * Remaining bytes: Action encoding * The rest of the bytes constitue the action-specific data. It is always the raw ABI encoding of a sequence of Solidity types To prevent any potential latency advantages for using HyperEVM to bypass the L1 mempool, order actions and vault transfers sent from CoreWriter are delayed onchain for a few seconds. This has no noticeable effect on UX because the end user has to wait for at least one small block confirmation. These onchain-delayed actions appear twice in the L1 explorer: first as an enqueuing and second as a HyperCore execution. | Action ID | Action | Fields | Solidity Type | Notes | | --------- | --------------------- | -------------------------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------
프로젝트로 돌아가기