本页面为社区翻译版本,仅供参考;内容以英文原版为准。
查看英文原版 ↗

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