本頁面為社群翻譯版本,僅供參考;內容以英文原版為準。
查看英文原版 ↗

HIP-3 部署者操作

用於部署和運營 builder 部署的永續 DEX 的 API 涉及以下 L1 操作:

// IMPORTANT: All lists of tuples should be lexographically sorted before signing
type PerpDeployAction =
  | {
      type: "perpDeploy";
      registerAsset2: RegisterAsset2;
    }
  | {
      type: "perpDeploy";
      registerAsset: RegisterAsset;
    }
  | {
      type: "perpDeploy";
      setOracle: SetOracle;
    }
  | {
      type: "perpDeploy";
      setFundingMultipliers: SetFundingMultipliers;
    }
  | {
      type: "perpDeploy";
      setFundingInterestRates: SetFundingInterestRates;
    }
  | {
      type: "perpDeploy";
      setFundingClamps: SetFundingClamps;
    }
  | {
      type: "perpDeploy";
      haltTrading: { coin: string; isHalted: boolean };
    }
  | {
      type: "perpDeploy";
      insertMarginTable: InsertMarginTable;
    }
  | {
      type: "perpDeploy";
      setMarginTableIds: SetMarginTableIds;
    }
  | {
      type: "perpDeploy";
      setFeeRecipient: { dex: string; feeRecipient: address };
    }
  | {
      type: "perpDeploy";
      setOpenInterestCaps: SetOpenInterestCaps;
    }
  | {
      type: "perpDeploy";
      setSubDeployers: { dex: string; subDeployers: Array<SubDeployerInput> };
    }
  | {
      type: "perpDeploy";
      setMarginModes: SetMarginModes;
    }
  | {
      type: "perpDeploy";
      setDeployerFees: SetDeployerFees;
    }
  | {
      type: "perpDeploy";
      setPerpAnnotation: SetPerpAnnotation;
    }
  | {
      type: "perpDeploy";
      disableDex: string;
    };

// User-signed action to transfer collateral between the user's DEX account and its backstop liquidator.
// ntl must be positive and a multiple of 1_000_000_000.
type Hip3LiquidatorTransferAction = {
  type: "hip3LiquidatorTransfer";
  dex: string;
  ntl: number; // Integer amount in millionths of a collateral token: 1_000_000_000 = 1,000 tokens
  isDeposit: boolean; // true deposits; false withdraws
};

/**
 * RegisterAsset2 can be called to initialize a new dex and register an asset at the same time.
 * If schema is not provided, then RegisterAsset can be called multiple times to register additional assets
 * for the provided dex.
 * @param maxGas - Max gas in native token wei. If not provided, then uses current deploy auction price.
 * If the max gas is 0, then a reserve deployment will be used.
 * A reserve deployment allows deployment at the current price of the gas auction, even if it has ended.
 * Currently, 7 reserve deployments are allowed.
 * IMPORTANT: A reserve deployment will be used regardless of whether the auction has completed, so deployers should query the auction status first.
 * @param assetRequest - Contains new asset listing parameters. See RegisterAssetRequest2 below for details.
 * @param dex - Name of the perp dex (2-4 lowercase characters)
 * @param schema - Contains new perp dex parameters. See PerpDexSchemaInput below for details.
 */
type RegisterAsset2 = {
  maxGas?: number;
  assetRequest: RegisterAssetRequest2;
  dex: string;
  schema?: PerpDexSchemaInput;
};

// Same as RegisterAsset2 but uses RegisterAssetRequest
type RegisterAsset = {
  maxGas?: number;
  assetRequest: RegisterAssetRequest;
  dex: string;
  schema?: PerpDexSchemaInput;
};

type RegisterAssetRequest2 = {
  coin: string;
  szDecimals: number;
  oraclePx: string;
  marginTableId: number;
  marginMode: "strictIsolated" | "noCross" | "normal"; // strictIsolated does not allow withdrawing of isolated margin from open positions
};

type RegisterAssetRequest = {
  coin: string;
  szDecimals: number;
  oraclePx: string;
  marginTableId: number;
  onlyIsolated: boolean;
};

/**
 * The markPxs outer list can be length 0, 1, or 2. The median of these inputs
 * along with the local mark price (median(best bid, best ask, last trade price))
 * is used as the new mark price update.
 *
 * SetOracle can be called multiple times but there must be at least 2.5 seconds between calls.
 *
 * Stale mark prices will be updated to the local mark price after 10 seconds of no updates.
 * This fallback counts as an update for purposes of the maximal update frequency.
 * This fallback behavior should not be relied upon. Deployers are expected to call setOracle every 3 seconds even with no changes.
 *
 * All prices are clamped to 10x the start of day value.
 * markPx moves are clamped to 1% from previous markPx.
 * markPx cannot be updated such that open interest would be 10x the open interest cap.
 * @param dex - Name of the perp dex
 * @param oraclePxs - A list (sorted by key) of asset and oracle prices.
 * @param markPxs - An outer list of inner lists (inner list sorted by key) of asset and mark prices.
 * @param externalPerpPxs - A list (sorted by key) of asset and external prices which prevent sudden mark price deviations.
 * Ideally externally determined by deployer, but could fall back to an EMA of recent mark prices.
 * Must include all assets.
 */
type SetOracle = {
  dex: string;
  oraclePxs: Array<[string, string]>;
  markPxs: Array<Array<[string, string]>>;
  externalPerpPxs: Array<[string, string]>;
};

/**
 * @param fullName - Full name of the perp dex
 * @param collateralToken - Collateral token index
 * @param oracleUpdater - User to update oracles. If not provided, then deployer is assumed to be oracle updater.
 */
type PerpDexSchemaInput = {
  fullName: string;
  collateralToken: int;
  oracleUpdater?: string;
};

/**
 * A sorted list of asset and funding multiplier.
 * Multipliers must be between 0 and 10 and are used to scale the funding rate.
 */
type SetFundingMultipliers = Array<[string, string]>;

/**
 * A sorted list of asset and 8 hour interest rate.
 * Interest rates must be between -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>;
};

在以下示例中,feeScale 即 SetDeployerFees 中的 scale 欄位。假設正常用戶費率爲 1 個單位且爲非對齊抵押品(x = y = 1)。userFeeToProtocol 和 userFeeToDeployer 是最終向用戶收取的費用單位。

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

如何查詢永續部署拍賣狀態,參見 https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-information-about-the-perp-deploy-auction。

持倉上限

Builder 部署的永續市場受兩種持倉上限約束:名義值(絕對倉位大小乘以標記價格之和)和數量(絕對倉位大小之和)。

名義持倉上限既對 DEX 內所有資產的持倉總和強制執行,也對單個資產強制執行。永續部署者可以爲每個資產設定自定義持倉上限,詳見 https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/hip-3-deployer-actions。

以數量計的持倉上限僅對單個資產強制執行,目前爲每資產固定 10 億(1B),因此合理的預設做法是設定 szDecimals,使得在初始標記價格下最小數量增量爲 1–10 美元。

兜底清算者

兜底清算者地址爲 0x4000000000000000000000000000000000000000 + {dex_index}。例如,第一個 HIP-3 DEX 的兜底清算者地址爲 0x4000000000000000000000000000000000000001。

節點用戶帳戶摘要

節點參數 --write-user-account-summaries <dex> 會將指定 HIP-3 DEX 的帳戶摘要寫入按小時生成的文件,路徑爲 ~/hl/data/dex_user_account_summaries/hourly/<date>/<hour>,其中 date 爲 YYYYMMDD。每行是一個 JSON 陣列 [time, messages],其中 time 是區塊時間,messages 是 DEX 上全部用戶的單個快照,或按用戶劃分的增量列表:

["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 爲帳戶價值,b 爲 balance = accountValue - unrealizedPnl,兩者均以該場所的抵押品代幣計價。每個文件的第一行,以及節點啓動後寫入的第一行,是快照。其餘各行包含摘要發生變化用戶的增量:該場所的預言機更新時爲每一個此類用戶,其他情況下僅爲參與成交、清算、資金費用支付或向該場所劃入/劃出資金(劃轉)的用戶。

HIP-3*(僅測試網)

Star 操作

HIP-3 場所在創建時可以通過在 PerpDexSchemaInput 中設定 isStar: true 被指定爲 HIP-3*。該可選布爾值預設爲 false。HIP-3* 在 HIP-3 規範之上啓用了若干功能,包括允許名單和代理用戶操作。

操作

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 } };
{
  "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 — 由一個用戶地址和應用於該用戶的一個代理操作組成的二元組。
  • setOracle — 更新預言機價格,詳見下文"預言機"一節。

代理操作

  • modifyApproval — { "modifyApproval": true } 將用戶加入允許名單,false 則移除該用戶並清除其標誌。移除一個未被批准的用戶是無操作。重新批准一個已批准的用戶也是無操作,並保留該用戶的標誌。被移除的用戶再次獲得批准時,將從預設標誌開始。
  • modifyBackstopLiquidatorApproval — { "modifyBackstopLiquidatorApproval": true } 允許用戶通過 hip3LiquidatorTransfer 向該場所的兜底清算者充值和提幣;false 撤銷該權限。用戶必須已通過 modifyApproval 獲得批准。
  • setReduceOnly — { "setReduceOnly": true } 限制已批准的用戶只能減少其在該場所的倉位。該用戶只能下只減倉(reduce-only)訂單和 TWAP、將訂單修改爲只減倉訂單以及撤單。{ "setReduceOnly": false } 恢復完整交易權限。
  • cancel — { "cancel": { "cancels": [{ "a": <asset>, "o": <oid> }] } },標準 cancel 交易所操作負載。按 oid 撤銷用戶的掛單。
  • cancelAll — { "cancelAll": { "assets": null } } 撤銷該用戶在此場所的所有掛單和 TWAP。{ "cancelAll": { "assets": [<asset>, ...] } } 僅撤銷所列資產的掛單和 TWAP。列表必須包含 1-10 個條目。
  • order — { "order": { "orders": [...], "grouping": "na" } },標準 order 交易所操作負載。每個訂單必須爲只減倉("r": true)。
  • sendAsset — { "sendAsset": { "destination": "0xUSER_C", "amount": "100.0" } }。將被代理用戶在 DEX 上的帳戶中的抵押品劃轉到同一場所中 destination 的帳戶。

預言機

HIP-3* 場所使用 setOracle star 部署操作來更新價格。oraclePxs 是按 key 排序的資產與現貨預言機價格列表。外部永續價格和標記價格基於部署者輸入的現貨預言機價格在鏈上推導。

  • 外部永續價格派生自主 DEX 中同名的資產,並將計價單位轉換爲 USDC。例如,test:BTC 使用 BTC 的外部永續價格。
  • 標記價格在鏈上按以下三者的中位數計算:
  1. 經中間價相對預言機價格溢價的指數移動平均值調整後的預言機價格,
  2. 外部永續價格,以及
  3. 本地標記價格(median(best bid, best ask, last trade price))。

如果僅有其中兩個價格可用,則加入本地標記價格的指數移動平均值作爲第三個輸入。

權限

對於 HIP-3*,SubDeployerInput.variant 還接受下表所示的對象。

操作 部署者 子部署者授權
modifyApproval 是 { "hip3Star": "modifyApproval" }
modifyBackstopLiquidatorApproval 是 { "hip3Star": "modifyBackstopLiquidatorApproval" }
setReduceOnly 是 { "hip3Star": "setReduceOnly" }
cancel 是 { "hip3Star": "cancel" }
cancelAll 是 { "hip3Star": "cancelAll" }
order 是 { "hip3Star": "order" }
sendAsset 是 { "hip3Star": "sendAsset" }
setOracle 是 { "hip3Star": "setOracle" }

每項授權僅覆蓋其自身的操作。例如,modifyApproval 授權不允許 modifyBackstopLiquidatorApproval、setReduceOnly 或 sendAsset。同樣,常規的 "setOracle" 授權(包括授予 oracleUpdater 的授權)不允許 setOracle star 操作。

用戶 star 狀態

userStarState info 請求返回用戶在其獲得過批准的每個 HIP-3* 場所上的批准狀態。對於此後已移除該用戶批准的場所,狀態爲 null。

{ "type": "userStarState", "user": "0xUSER_A" }
{
  "dexToState": {
    "test": {
      "isReduceOnly": false,
      "isBackstopLiquidatorDepositAllowed": true
    },
    "demo": null
  }
}
英文官方來源: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/hip-3-deployer-actions-1
原文擷取日期: · 鏡像建置日期: · 社群翻譯,以英文原版為準
非官方社群鏡像與翻譯,內容版權歸 Hyperliquid 所有,以英文原版為準。 來源: https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/hip-3-deployer-actions-1